case 1: return one row of data,
sqlCommand cm = new ...
int qty = (int)cm.ExecuteScalar();
case 2: return multiple rows of data
SqlDataReader dataReader = cm.ExectueReader(CommandBehavior.CloseConnection);
while(dataReader.read()){
Console.Write(dataReader.getString(0)..)
}
dataReader.Close();
cm.Close();
Case 3: no return value(e.g. insert, update, delete operations)
cm.CommandText = ...
cm.CommandType = CommandType.StoreProcedure;
cm.Connect = cn;
cn.open();
int n = cm.ExecuteNonQuery();
cn.Close();
sqlCommand cm = new ...
int qty = (int)cm.ExecuteScalar();
case 2: return multiple rows of data
SqlDataReader dataReader = cm.ExectueReader(CommandBehavior.CloseConnection);
while(dataReader.read()){
Console.Write(dataReader.getString(0)..)
}
dataReader.Close();
cm.Close();
Case 3: no return value(e.g. insert, update, delete operations)
cm.CommandText = ...
cm.CommandType = CommandType.StoreProcedure;
cm.Connect = cn;
cn.open();
int n = cm.ExecuteNonQuery();
cn.Close();
Comments
Post a Comment