Leito web

Trying connect

In Scripts on 14 Febrero, 2008 at 11:35 pm

String myConnString = “User ID=<username>;password=<strong password>;Initial Catalog=pubs;Data Source=myServer”;
SqlConnection myConnection = new SqlConnection(myConnString);
SqlCommand myCommand = new SqlCommand();
SqlDataReader myReader ;

myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Connection = myConnection;
myCommand.CommandText = “MyProc”;
int RecordCount=0;

try
{
myConnection.Open();
myReader = myCommand.ExecuteReader();

while (myReader.Read())
{
//Write logic to process data for the first result.
RecordCount = RecordCount + 1;
}
MessageBox.Show(”Total number of Authors: ” + RecordCount.ToString());

myReader.NextResult();
RecordCount = 0;

while (myReader.Read())
{
//Write logic to process data for the second result.
RecordCount = RecordCount + 1;
}
MessageBox.Show(”Authors from California: ” + RecordCount.ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
myConnection.Close();<

All comments are screened for appropriateness. Commenting is a privilege, not a right. Good comments will be cherished, bad comments will be deleted.