62,046
社区成员
发帖
与我相关
我的任务
分享
string SavePaper()
{
string sQUES_ID = "";
connection.Open();
sSql = "insert into t_Paper where values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
SqlCommand cmd = new SqlCommand(sSql, connection);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
sQUES_ID = dr["paper_id"].ToString();
connection.Close();
return sQUES_ID;
}
sSql = "insert into t_Paper values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
try[/quote]
这个,和我原先的代码是一样的呀,,,感觉没执行insert语句,是不是insert不能用ExecuteReader()?[/quote]
我上面不是给你一个方法了么 你试了么?[/quote]
试了,没有插进去[/quote]
这个表就两个字段了sSql = "insert into t_Paper values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
try[/quote]
这个,和我原先的代码是一样的呀,,,感觉没执行insert语句,是不是insert不能用ExecuteReader()?[/quote]
我上面不是给你一个方法了么 你试了么?[/quote]
试了,没有插进去sSql = "insert into t_Paper values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
try[/quote]
这个,和我原先的代码是一样的呀,,,感觉没执行insert语句,是不是insert不能用ExecuteReader()?[/quote]
我上面不是给你一个方法了么 你试了么?sSql = "insert into t_Paper values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
try[/quote]
这个,和我原先的代码是一样的呀,,,感觉没执行insert语句,是不是insert不能用ExecuteReader()?sSql = "insert into t_Paper values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
trystring SavePaper()
{
string sQUES_ID = "";
connection.Open();
sSql = "insert into t_Paper where values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
SqlCommand cmd = new SqlCommand(sSql, connection);
object obj = cmd.ExecuteScalar();
sQUES_ID = obj.ToString();
connection.Close();
return sQUES_ID;
}
[/quote]
上面的where去掉 我是用你之前写的语句的string SavePaper()
{
string sQUES_ID = "";
connection.Open();
sSql = "insert into t_Paper where values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
SqlCommand cmd = new SqlCommand(sSql, connection);
object obj = cmd.ExecuteScalar();
sQUES_ID = obj.ToString();
connection.Close();
return sQUES_ID;
}
string SavePaper()
{
string sQUES_ID = "";
connection.Open();
sSql = "insert into t_Paper values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
SqlCommand cmd = new SqlCommand(sSql, connection);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
sQUES_ID = dr["paper_id"].ToString();
connection.Close();
return sQUES_ID;
}
string SavePaper()
{
string sQUES_ID = "";
connection.Open();
sSql = "insert into t_Paper where values('" + txtPaperName.Text.Trim() + "');"
+ "select @@identity as paper_id";
SqlCommand cmd = new SqlCommand(sSql, connection);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
sQUES_ID = dr["paper_id"].ToString();
connection.Close();
return sQUES_ID;
}