Inicio > Scripts > Trying connect

Trying connect

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();<

Categorías:Scripts Etiquetas:, , , , ,
  1. Aún no hay comentarios.
  1. Aún no hay trackbacks