z
 
:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:        
  passwords:  
 

Resources

Finding Correct Content Managemet System
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Workflow Managemet Systems
Workflow management is a crucial component in organizing a variety of business processes so that they benefit the business as a whole and increase profitability...

Using the Power of Content Management Systems
With page editors that resemble a word processor program, adding content with a CMS interface is simple and fun. Most CMS software also allows you to change the location of your content pages and links easily, while the back end processes takes care of updating the links throughout your site...

Content Management Systems (CMS): What They Are And Why We Love Them
In the past, individuals who took interest in having and operating their own websites were burdened with the task of learning HTML, DHTML, and other web-based technologies such as JavaScript and CSS. The only alternative to this was, unfortunately, to pocket the expenses and costs required to pay a web developer to build and maintain it for them...

Outsourcing
Post your project for outsourcing and get bids from qualified programmers, designers, interpreters, copywriters.


 

Code Walkthroughs

Datagrid Formatting the Data
We are able to format the content of the datagrid cell by one of two simple methods, dependant upon whether the column is a bound column or whether it is a template column. In our example we shall format the column to have to digits after the decimal point , followed by a...

Datagrid Highlight a Row With Click Through
It is relatively easy to add alternating colours to the rows in your datagrid. However, when we move the mouse over the rows we may want to highlight this row, and possibly to add the option of a click through based on the row selected...

Add a Delete Button to a Datagrid
To add a delete button to a datagrid follows a similar process to adding an edit button. In the datagrid header...

Add an Edit Button to a Datagrid
The datagrid has a predefined editColumn for handling the editing of a datagrid. Adding this simple column definition to a datagrid adds a powerful feature. When a row is not in edit mode the column item shows the word...

Making a Datagrid Row Editable
Two of the most popular methods of editing a datagrid in asp.net are to either select the row and take the user off to a different presentation of the data, or to change the formatting of the row presented in the database with appropriate edit text boxes, checkboxes and...

Adding Tooltips to Datagrid Rows
Adding tooltips to datagrid rows is easy, assuming that you have already created the code for adding row highlighting. In this article I shall assume that you have already read the article entitled Datagrid Highlight a Row With Click Through...

Binding a Datagrid to an Access Database
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Adding Data to a DropDownList
The aim of this article is to answer the question 'How do I add items to a DropDownList?' Initially as part of the declaration for the DropDownList we can also define a number of items, much in the same way as in classic ASP...

Getting Current Date Time
In classic ASP we had now() which would return the current date and time. For asp.net this no longer exists. So what should we use...

Test if File Exists
Sometimes, in order to reduce our chance of error, when working with the filesystem in ASP.NET, we need to determine wether a file exists before performing an action on it. The following short piece of code will enable us to test whether a file exists...

Using Javascript with ASP.NET Form Elements
Adding simple pieces of Javascript to an Asp.net page can be acheived by adding to the attributes of the particular imagebutton or linkbutton. if its normal ASP.Net Button then you can...

Regular Expressions
In the table below we list the characters used in .Net regular expressions, together with their meaning, But first...

Authentication in Asp.net
Forms authentication in ASP.Net is far more easier and safe than Asp 3. It is possible to place a web.config file in any directory of a web site.Therefore, we are able to make most of a web site public, whilst providing authentication on, say, one directory...

Discussion Forums

General ASP.NET

.Net Programming

cSharp Home

Sql Server Home

Javascript / Client Side Development

IT Jobs

Ajax Programming

Ruby on Rails Development

Perl Programming

C Programming Language

C++ Programming

Python Programming Language

Laptop Suggestions?

TCL Scripting

Fortran Programming

Scheme Programming

31. ADO.NET

FAQ Home
   31.1 What is the Performance comparison between DataSet and DataReader?
   31.2 How to get the count of records in the Database table using the DataSet?
   31.3 How to check if the Dataset has records?
   31.4 How to retrieve value of a field in a dataset?
   31.5 How to filter the data in the DataView and display it in some DataControl?
   31.6 How to truncate the data in the column?
   31.7 How to find the null fields in the datareader?
   31.8 How to Implement a DataSet SELECT DISTINCT Helper Class?
   31.9 I am running the query SQL="Select name from profile where proID=1"; and I am getting the result in Dataset dsdata. Now how do I read the text from the dataset and assign it to textbox1.text ?
   31.10 How to query the database to get all the Table names?
   31.11 How to View one record per page in ASP.NET?
   31.12 How to insert data in database using Textboxes?
   31.13 When I try to enter a null value for DataTime in Database I get error message "String was not recognized as a valid DateTime" or "Value of type 'System.DBNull' cannot be converted to 'String'"?
   31.14 How to use Parameterized queries in ASP.NET?
   31.15 How to filter distinct records from a normal Select query and display in a web control?
   31.16 A field with bit data type value when displayed on a web page shows true/ false how to display a bit value as 1/0?
   31.17 When I try to enter null value to DateTime field in database it is saved as 1/1/1900 12:00:00 AM?
   31.18 How to use Stored Procedures in ASP.NET?
   31.19 How to display multiple records using DataTable.Select?
   31.20 How to get the count of items in a dataReader?
   31.21 How to check EOF with SqlDataReader?
   31.22 How to filter xml data and display data in the DataGrid?
   31.23 Why do I get the error message "ExecuteReader requires an open and available Connection. The connection's current state is Closed"?
   31.24 Why do I get the error message "The ConnectionString property has not been initialized"?
   31.25 I get the error message "Keyword not supported: 'provider'", when using Sql Server why?
   31.26 Why do I get the error message "ExecuteReader: Connection property has not been initialized"?
   31.27 Why do I get the error message "There is already an open DataReader associated with this Connection which must be closed first."?
   31.28 I get the error message "Cast from type DBNull to type String is not valid." when I try to display DataReader values on form?
   31.29 What is the significance of CommandBehavior.CloseConnection?
   31.30 How to maintain Line feeds when saving data to a database?
   31.31 How to use the Same DataReader to populate two different ListBoxes?
   31.32 How to resolve the error message "Cannot implicitly convert type 'string' to 'System.DateTime' " when using a DataReader?
   31.33 Why do I get the error message "Value cannot be null. Parameter name: dataSet "?
   31.34 Why do I get the error message "The SelectCommand property has not been initialized before calling 'Fill'. "?
   31.35 How to use OleDb DataSet?
   31.36 How to use OleDb DataReader?
   31.37 How to loop through a Dataset to display all records?



31.1 What is the Performance comparison between DataSet and DataReader?


Refer Performance Comparison: Data Access Techniques


31.2 How to get the count of records in the Database table using the DataSet?


VB.NET


ds.Tables(0).Rows.Count


C#


ds.Tables[0].Rows.Count ;



31.3 How to check if the Dataset has records?


VB.NET


if ds.Tables(0).Rows.Count= 0 then
     'No record
else
     'Record Found
end if


C#


if (ds.Tables[0].Rows.Count == 0 )
{
     //No record
}
else
{
     //Record Found
}



31.4 How to retrieve value of a field in a dataset?


VB.NET


ds.Tables("TableName").Rows(0)("ColumnName")


C#


ds.Tables["TableName"].Rows[0]["ColumnName"];


where TableName and ColumnName could be also integer (not in quotes then) to indicate you refer to the table's or column's index position. Rows(0) indicates the first and only row in DataTable's Rows collection


31.5 How to filter the data in the DataView and display it in some DataControl?


VB.NET


Dim thefilter as string = "fieldname=' ' "
dbDataView.RowFilter = thefilter               
Repeater1.DataSource = dbDataView
Repeater.DataBind()


C#


string thefilter = "fieldname=' ' ";
dbDataView.RowFilter = thefilter;                    
Repeater1.DataSource = dbDataView;
Repeater.DataBind();



31.6 How to truncate the data in the column?


VB.NET


Protected function TruncateData( Byval strNotes as string)
If strNotes.Length > 20 then
     Return strNotes.Substring(0,20) + "..."
Else
     return strnotes
End function


C#


protected string TruncateData( string strNotes )
{
if (strNotes.Length > 20)
{
     return strNotes.Substring(0,20) + "...";
}
else
{
     return strNotes;
}
}



31.7 How to find the null fields in the datareader?


VB.NET


If dbReader("fieldname").Tostring= DBnull.Value.ToString()
     'Empty field value
Else
     'Display value
End if


C#


if (dbReader["fieldname").ToString() == DBNull.Value.ToString() )
{
     //Empty field value
}
else
{
     //display Value
}



31.8 How to Implement a DataSet SELECT DISTINCT Helper Class?


VB.NET
Sample code 1
C#
Sample Code 2


31.9 I am running the query SQL="Select name from profile where proID=1"; and I am getting the result in Dataset dsdata. Now how do I read the text from the dataset and assign it to textbox1.text ?


VB.NET


dsData.Tables(0).Rows(0)("FieldName").ToString()


C#


dsData.Tables[0].Rows[0]["FieldName"].ToString()



31.10 How to query the database to get all the Table names?



SELECT * FROM information_schema.tables where Table_type='BASE TABLE'



31.11 How to View one record per page in ASP.NET?



<asp:label id="Label2" style="Z-INDEX: 106; LEFT: 111px; POSITION: absolute; TOP: 83px"
     runat="server">Product ID</asp:label>
<asp:label id="Label1" style="Z-INDEX: 105; LEFT: 110px; POSITION: absolute; TOP: 43px"
     runat="server">Product Name</asp:label>
<asp:textbox id="txtProductName" style="Z-INDEX: 104; LEFT: 206px; POSITION: absolute; TOP: 83px"
     runat="server" OnDataBinding="txtDataBind"></asp:textbox>
<asp:textbox id="txtProductid" style="Z-INDEX: 103; LEFT: 204px; POSITION: absolute; TOP: 43px"
     runat="server">
<asp:button id="btnPrevious" style="Z-INDEX: 102; LEFT: 137px; POSITION: absolute; TOP: 126px"
     runat="server" Text="Previous" OnClick ="PrevBtn"></asp:button>
<asp:button id="btnNext" style="Z-INDEX: 101; LEFT: 243px; POSITION: absolute; TOP: 126px"
     runat="server" Text="Next" OnClick ="NextBtn"></asp:button>


VB.NET


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     'Put user code to initialize the page here
     Try
          'Fill the DataSet
          If Not Page.IsPostBack Then
               ViewState("CurrentPos") = 0
               Me.DataBind()
          End If
     Catch ex As Exception
          Response.Write(ex.Message & ex.StackTrace)
     End Try
End Sub

protected Sub NextBtn(ByVal sender As System.Object, ByVal e As System.EventArgs)
Try
     Dim CurrentPos As Integer = CType(ViewState("CurrentPos"), Integer)
     CurrentPos += 1
     If CurrentPos > ds.Tables(0).Rows.Count Then
          CurrentPos -= 1
     End If
     ViewState("CurrentPos") = CurrentPos
     Me.DataBind()
Catch ex As Exception
     Response.Write(ex.Message)
End Try
End S