我想使用sql loader添加对表中重复记录插入的检查。
例如:当在表中找到重复记录时插入行时,它应该是条件。
答案 0 :(得分:1)
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
string strSQL = "SELECT * FROM tablename WHERE your condition"; //like name='"+textbox.text+"'";
da.SelectCommand = new SqlCommand(strSQL);
da.SelectCommand.Connection = con;
da.Fill(dt);
if (dt.Rows.Count > 0) // Means data already present
{
lblmsg.Text = "This data is already added!";
}
else if (dt.Rows.Count == 0)
{
// Insert your value
}