为什么asp.net中update没用我把update语句放sqlsever中执行了下也不行这是为什么
publicpartialclassweb:System.Web.UI.Page{privateSqlDataReadermyreader;protectedvoidPa...
public partial class web : System.Web.UI.Page
{
private SqlDataReader myreader;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=123-THINK;uid=sa;pwd=sasasa;database=hxl");
conn.Open();
string update = "update class set link='www.jiangnan.edu.cn' where id=1";
SqlCommand cmd = new SqlCommand(update,conn);
string select = "select id,link,content from class where id=1";
cmd.CommandText = select;
myreader = cmd.ExecuteReader();
if (myreader.Read())
{
label1.Text = myreader["id"].ToString().Trim();
label2.Text = myreader["link"].ToString().Trim();
label3.Text = myreader["content"].ToString().Trim();
}
conn.Close();
}
} 展开
{
private SqlDataReader myreader;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=123-THINK;uid=sa;pwd=sasasa;database=hxl");
conn.Open();
string update = "update class set link='www.jiangnan.edu.cn' where id=1";
SqlCommand cmd = new SqlCommand(update,conn);
string select = "select id,link,content from class where id=1";
cmd.CommandText = select;
myreader = cmd.ExecuteReader();
if (myreader.Read())
{
label1.Text = myreader["id"].ToString().Trim();
label2.Text = myreader["link"].ToString().Trim();
label3.Text = myreader["content"].ToString().Trim();
}
conn.Close();
}
} 展开
2个回答
展开全部
ASP.NET中更新数据库是这样写的
SqlConnection conn = new SqlConnection("server=123-THINK;uid=sa;pwd=sasasa;database=hxl");
conn.Open();
string update = "update class set link='www.jiangnan.edu.cn' where id=1";
SqlCommand cmd = new SqlCommand(update,conn);
if(myCmd.ExecuteNonQuery()>0){
// 这里写更新成功后的代码……
//如果要把更新成功后的记录读出来的话,就这样写
string select = "select id,link,content from class where id=1";
SqlCommand cmdSelect = new SqlCommand(select,conn);
myreader = cmd.ExecuteReader();
if (myreader.Read())
{
label1.Text = myreader["id"].ToString().Trim();
label2.Text = myreader["link"].ToString().Trim();
label3.Text = myreader["content"].ToString().Trim();
}
conn.Close();
}//if(myCmd.ExecuteNonQuery()>0)的结尾括号
SqlConnection conn = new SqlConnection("server=123-THINK;uid=sa;pwd=sasasa;database=hxl");
conn.Open();
string update = "update class set link='www.jiangnan.edu.cn' where id=1";
SqlCommand cmd = new SqlCommand(update,conn);
if(myCmd.ExecuteNonQuery()>0){
// 这里写更新成功后的代码……
//如果要把更新成功后的记录读出来的话,就这样写
string select = "select id,link,content from class where id=1";
SqlCommand cmdSelect = new SqlCommand(select,conn);
myreader = cmd.ExecuteReader();
if (myreader.Read())
{
label1.Text = myreader["id"].ToString().Trim();
label2.Text = myreader["link"].ToString().Trim();
label3.Text = myreader["content"].ToString().Trim();
}
conn.Close();
}//if(myCmd.ExecuteNonQuery()>0)的结尾括号
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询