How do i check if there is a same id when you trying to add a data to database?
For example, if i have Name \"Leo Chan\" with id \'5\' in the list
and when i wan
DataTable dt = new DataTable();
string query = string.format("SELECT * from table WHERE ID = {0}", ID);
using(SqlDataAdapter sda = new SqlAdapter(query, con))
{
sda.fill(dt)
if(dt.Rows.count > 0)
{
showErrorMessage();
return;
}
}
I know there are multiple ways to read from a database, but I like using SqlDataAdapters, because you really don't have to create a SqlConnection or a SqlCommand. SqlDataAdapter does it for you.