我初学.net现在试做一个数据库操作,代理如下:
string StrConn="server=PCServer;database=DB;uid=sa;pwd=sa";
string SQL = "select top 1 UserName from Member";
string TmpStr="";

SqlConnection Conns = new System.Data.SqlClient.SqlConnection(StrConn);
Conns.Open();SqlCommand cmd = new SqlCommand(SQL,Conns);

SqlDataReader DataRow = cmd.ExecuteReader(CommandBehavior.SingleRow);

while (DataRow.Read()){
  TmpStr =DataRow.GetString(0);
  DataRow.NextResult();
}
DataRow.Close();
Conns.Close();
textBox1.Text = TmpStr;
其它Conns.Open在按F5(调试)下执行报出错误:
未处理的“System.NullReferenceException”类型的异常出现在 system.data.dll 中。
其他信息: 未将对象引用设置到对象的实例。
如果按CTRL+F5(不调试)运行正常.为什么呢?