在TEXTBOX中输入查询条件,点击BUTTON,如果查询条件在数据库中某表中存在,则在DATAGRIVEW中显示该条件对应列的内容
添加和删除也发我看看,谢谢了,
strConString是随便写的,还是有什么意义啊。
static string strConString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
是连接字符串
添加:
protected void Button2_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(strConString))
{
con.Open();
string sql = "insert into userInfo values(@userName)";
SqlCommand com = new SqlCommand(sql, con);
com.Parameters.Add("@userName", txtUserName.Text.Trim());
com.ExecuteNonQuery();
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('添加成功!');location.href='Default6.aspx'", true);
}
}
删除:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
using (SqlConnection con = new SqlConnection(strConString))
{
con.Open();
string sql = "delete from userInfo where userId='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlCommand com = new SqlCommand(sql, con);
com.ExecuteNonQuery();
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除成功!');location.href='Default6.aspx'", true);
}
}
那个删除我也是要写在一个BUTTON的方法里的
追答这个的话不好做哦,一般是在GridView1_RowDeleting这个事件里面做,或者在rowcommand事件里面做
追问哦,那谢谢了。果断把分给你先、