How to Implement a DataSet SELECT DISTINCT Helper Class
VB.NET Sample code 1 C# Sample Code 2
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>’); }
Why doesn’t changes made to some of my properties don’t get saved in the aspx file during design time?
Nested properties in your controls should be marked with the NotifyParentProperty(true) attribute in order for the designer to get notified that it’s value has changed. For example, the following property (SubProperty) declaration should include the above mentioned attribute, for the designer to persist changes to that property during design-time: myControl.SomeComplexProperty.SubProperty = ‘some value’;
Why doesn’t my properties tagged with the PersistenceMode.InnerProperty attribute get saved in the aspx file?
All string type properties get saved as attributes of the parent tag inspite of the InnerProperty attribute setting. In fact, setting the InnerProperty attribute might prevent the property from getting saved at all. For example, in the property declaration below: [C#] [ Category(‘Appearance’), NotifyParentProperty(true), PersistenceMode(PersistenceMode.Attribute), // This should always be Attribute, not anything else like InnerProperty. ] public string Text{get{return text;}set{text = value;}}