Reputation: 1
I want to add a check for duplicate record inserting in a table using sql loader.
For eg: while inserting rows in a table if it found a duplicate record, it should go for a condition.
Upvotes: 0
Views: 561
Reputation: 435
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
}
Upvotes: 1