kvnsdr
asked on
C# vs. Visual Studio .NET Coding Practices....????
I feel the most confusing aspect in learning C# .NET Visual Studio is finding code on the Internet (below) that appears to be good C# coding, however I'm not sure how to use the 'automatic' drag-n-drop features to avoid coding the old way.
Q. How would the code snippet below look if coded using C# .NET Visual Studio???
private void PopAbsent()
{
listBox2.Items.Clear();
//List Absent Reps
listBox2.BeginUpdate();
string v_tsql = "SELECT RTRIM([rep]) FROM Supportstats.dbo.absent_re p";
SqlConnection myConnection = new SqlConnection(v_sqlconnstr ing);
SqlCommand myCommand = new SqlCommand(v_tsql,myConnec tion);
try
{
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
string v_repname = myReader.GetString(0);
listBox2.Items.Add(v_repna me);
}
myReader.Close();
myConnection.Close();
}
catch
{
MessageBox.Show("Unable establish SQL Connection.\nVarify settings and try again.", "SQL Connection Test: Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
}
listBox2.EndUpdate();
}
Q. How would the code snippet below look if coded using C# .NET Visual Studio???
private void PopAbsent()
{
listBox2.Items.Clear();
//List Absent Reps
listBox2.BeginUpdate();
string v_tsql = "SELECT RTRIM([rep]) FROM Supportstats.dbo.absent_re
SqlConnection myConnection = new SqlConnection(v_sqlconnstr
SqlCommand myCommand = new SqlCommand(v_tsql,myConnec
try
{
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
string v_repname = myReader.GetString(0);
listBox2.Items.Add(v_repna
}
myReader.Close();
myConnection.Close();
}
catch
{
MessageBox.Show("Unable establish SQL Connection.\nVarify settings and try again.", "SQL Connection Test: Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation
}
listBox2.EndUpdate();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.