string str2 = TextBox2.Text.ToString();//姓名
string str3 = TextBox3.Text.ToString();//性别
string str4 = TextBox4.Text.ToString(); //出生
string str5 = TextBox5.Text.ToString(); //学历
string str6 = TextBox6.Text.ToString();//专业
string str7 = TextBox7.Text.ToString();//职称
string str8 = TextBox8.Text.ToString();//籍贯
string str9 = TextBox9.Text.ToString();//备注
string ingo = "update staff_info set sex='" + str3 + "',birth='" + str4 + "',qualifications='" + str5 + "',zhuanye='" + str6 + "',zhicheng='" + str7 + "',jiguan='" + str8 + "',beizhu='" + str9 + "' where staff_name='" + Session["UserId"].ToString()+ "'";
string insert = "insert into staff_info(staff_name,sex,birth,qualifications,zhicheng,zhuanye,jiguan,beizhu) values('" + str2 + "','" + str3 + "','" + str4 + "','" + str5 + "','" + str6 + "','" + str7 + "','" + str8 + "','" + str9 + "')";
string staff_name =this.Session["staff_info"].ToString(); SqlConnection con3 = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
SqlCommand com3 = new SqlCommand("select count(*) from staff_info where staff_name ='" + staff_name+"'", con3);
com3.Connection.Open();
int i1 = (int)com3.ExecuteScalar();
com3.Connection.Close();
if (i1 > 0)
{
SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
strcon.Open();
SqlCommand scd = new SqlCommand(ingo, strcon);
scd.ExecuteNonQuery();
strcon.Close();
Response.Write("<script>alert('更新成功!')</script>");
}
else//数据库没有姓名的记录
{
SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
strcon.Open();
SqlCommand scd = new SqlCommand(insert, strcon);
scd.ExecuteNonQuery();
strcon.Close();
Response.Write("<script>alert('添加成功!')</script>");
}
点击更新后,但是还是无法更新数据库,问题在哪里呢?各位帮帮忙。。
string str3 = TextBox3.Text.ToString();//性别
string str4 = TextBox4.Text.ToString(); //出生
string str5 = TextBox5.Text.ToString(); //学历
string str6 = TextBox6.Text.ToString();//专业
string str7 = TextBox7.Text.ToString();//职称
string str8 = TextBox8.Text.ToString();//籍贯
string str9 = TextBox9.Text.ToString();//备注
string ingo = "update staff_info set sex='" + str3 + "',birth='" + str4 + "',qualifications='" + str5 + "',zhuanye='" + str6 + "',zhicheng='" + str7 + "',jiguan='" + str8 + "',beizhu='" + str9 + "' where staff_name='" + Session["UserId"].ToString()+ "'";
string insert = "insert into staff_info(staff_name,sex,birth,qualifications,zhicheng,zhuanye,jiguan,beizhu) values('" + str2 + "','" + str3 + "','" + str4 + "','" + str5 + "','" + str6 + "','" + str7 + "','" + str8 + "','" + str9 + "')";
string staff_name =this.Session["staff_info"].ToString(); SqlConnection con3 = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
SqlCommand com3 = new SqlCommand("select count(*) from staff_info where staff_name ='" + staff_name+"'", con3);
com3.Connection.Open();
int i1 = (int)com3.ExecuteScalar();
com3.Connection.Close();
if (i1 > 0)
{
SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
strcon.Open();
SqlCommand scd = new SqlCommand(ingo, strcon);
scd.ExecuteNonQuery();
strcon.Close();
Response.Write("<script>alert('更新成功!')</script>");
}
else//数据库没有姓名的记录
{
SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
strcon.Open();
SqlCommand scd = new SqlCommand(insert, strcon);
scd.ExecuteNonQuery();
strcon.Close();
Response.Write("<script>alert('添加成功!')</script>");
}
点击更新后,但是还是无法更新数据库,问题在哪里呢?各位帮帮忙。。
string staff_name =this.Session["staff_info"].ToString(); SqlConnection con3 = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
SqlCommand com3 = new SqlCommand("select count(*) from staff_info where staff_name ='" + staff_name+"'", con3);
com3.Connection.Open();
int i1 = (int)com3.ExecuteScalar();
com3.Connection.Close();
if (i1 > 0)
{
SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
strcon.Open();
SqlCommand scd = new SqlCommand(ingo, strcon);
int cnt = scd.ExecuteNonQuery(); // 可以得到受影响的行数
strcon.Close();
Response.Write(" <script>alert('更新成功!') </script>");
}
else//数据库没有姓名的记录
{
SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
strcon.Open();
SqlCommand scd = new SqlCommand(insert, strcon);
int cnt = scd.ExecuteNonQuery(); //// 可以得到受影响的行数
strcon.Close();
Response.Write(" <script>alert('添加成功!') </script>");
}
我再说下问题,是当我点更新以后
即当调用
if (i1 > 0)
{
SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["project_systemConnectionString"]);
strcon.Open();
SqlCommand scd = new SqlCommand(ingo, strcon);
int cnt = scd.ExecuteNonQuery(); // 可以得到受影响的行数
strcon.Close();
Response.Write(" <script>alert('更新成功!') </script>");
}
后显示了 ”更新成功“,但是却没有在数据库改变数据,也就是说那个update没有成功使用就这里是什么问题,帮忙看看,谢谢了
select count(*) from staff_info where staff_name ='你定义的变量'
我和同学商量了下,不过不知道怎么改,只是在page_load里加了一个判定 ispostback()。但是还是读入的还是原来的数据,应该怎么改呢?