对表插入数据:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = db.createconnection();
con.Open();
string str = "insert into [zuname] (zuname,beizhu) values ('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "') where (zuname)<>('"+this.TextBox1.Text+"')";
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('添加成功!');</script>");
con.Close();
bind();
}
运行出现where语句附近有错。。把<>改成!=也不行
不知道还有什么其他比较好的方法。。谢谢!
------解决方案--------------------------------------------------------
如何判断【zuname】里面已经存在数据比较简单。。。
- C# code
SqlConnection conn = .....string sql = "select * from [zuname] where zuname= '你的条件'";try{ SqlDataAdapter myDapter=new SqlDataAdapter(mysql,conn); DataSet ds=new DataSet(); myDapter.Fill(ds); DataTable dt = ds.Tables[0]; if(dt.Rows.Count>=1) { 存在数据 } else { 不存在数据 }}catch{ 异常}