What is the best place to store Database connection string?

In Web.Config, you would add a key to the AppSettings Section: <appSettings> <add key=’MyDBConnection’ value=’server=<ServerName>;uid=<Username>;pwd=;database=<DBName>’ /> </appSettings> Example : <add key=’ConnectionString’ value= ‘Server=localhost;uid=sa;pwd=;database=northwind’ /> Then, in your ASP.Net application – just refer to it like this: Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings(‘ConnectionString’))

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 }

How to check EOF with SqlDataReader

If you are using the Framework 1.1 , use HasRows For Framework < 1.1 VB.NET Dim myconnection As SqlConnection Dim mycmd As SqlCommand Dim strSql As String Dim myReader As SqlDataReader myconnection = New SqlConnection(‘Server=localhost;uid=sa;password=;database=northwind;’) strSql = ‘Select count(*) from employees;Select * from employees’ mycmd = New SqlCommand(strSql, myconnection) myconnection.Open() Dim count As Integer = CInt(mycmd.ExecuteScalar()) myReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection) If count = 0 Then Response.Write(‘No records found’) Else myReader.NextResult() While myReader.Read() Response.Write(myReader(‘Employeeid’).ToString() + ‘<BR>’) End While End If C# SqlConnection myconnection ; SqlCommand mycmd ; string strSql ; SqlDataReader myReader ; myconnection = new SqlConnection(‘Server=localhost;uid=sa;password=;database=northwind;’); strSql = ‘Select count(*) from employees;Select * from employees’; mycmd = new SqlCommand(strSql, myconnection); myconnection.Open(); int count=(int) mycmd.ExecuteScalar() ; myReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection); if (count==0 ) { Response.Write(‘No records found’); } else { myReader.NextResult (); while(myReader.Read ()) { Response.Write(myReader[‘Employeeid’].ToString () + ‘<br>’); } }

How to print out all the variables in the Session

VB.NET Dim strKey as string For Each strKey In Session.Keys Response.Write(strKey + ‘ : ‘ + Session(strKey).ToString() + ‘<br>’) Next C# foreach (string strKey in Session.Keys) { Response.Write(strKey + ‘ : ‘ + Session[strKey].ToString() + ‘<br>’); }