string sql = "insert into golfclubs values('"+clubName+"','"+Area+"','"+in_date+"');select @@identity as 'maxid'";
string id = "";
try
{
SqlCommand dtc = new SqlCommand(sql,odbc.getConn());
SqlDataReader dtr = dtc.ExecuteReader();
id = dtr["maxid"].ToString();
dtr.Close();
}
catch(Exception exc)
{
throw exc;
}
------------------------------------------
提示错误:在没有任何数据时进行无效的读取尝试
请高手指点,哪错了。
string id = "";
try
{
SqlCommand dtc = new SqlCommand(sql,odbc.getConn());
SqlDataReader dtr = dtc.ExecuteReader();
id = dtr["maxid"].ToString();
dtr.Close();
}
catch(Exception exc)
{
throw exc;
}
------------------------------------------
提示错误:在没有任何数据时进行无效的读取尝试
请高手指点,哪错了。
{
// 使用数据
}
id = dtr["maxid"].ToString();
id = dtr["maxid"].ToString();