110,025
社区成员




ClientScript.RegisterStartupScript(this.GetType(), "", "alert('已经存在该信息');", true);
//连接字符串
string connectionSting = @"Data Source=Source;Initial Catalog=database;Persist Security Info=True;User ID=sa;Password=password";
SqlConnection myConnection = new SqlConnection(connectionSting);
//打开数据库
myConnection.Open();
//检查有无数据
DataSet ds = new DataSet();
string oda = "SELECT * FROM table where id=10;
SqlDataAdapter df = new SqlDataAdapter(oda, myConnection);
df.Fill(ds, "tablename");
if (ds.Tables[第几列].Rows.Count > 0)
{
MessageBox.show("数据存在!")
}
SqlConnection conn = new SqlConnection(SqlDataSource1.ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(SqlDataSource1.SelectCommand.ToString());
SqlDataReader sdr = cmd.ExecuteReader();
if(sdr.Read())
//进行数据插入操作
else
MessageBox.Show("已经存在该数据");
using(SqlConnection conn = new SqlConnection("连接字符串"))
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from table where ID=10",conn);
SqlDataReader sdr = cmd.ExecuteReader();
if(sdr.Read())
MessageBox.Show("已经存在该数据");
else
//进行数据插入操作
}