I have a datatable that populates from my database. I have a function to add and update data, but now I would like to check if the data exists or not. But I have to check two things.
If there is data in the database, make sure that it is turned on or off, if it is turned on, then you need to return the message = "Data exists in the table" else "Data is disabled."
bool nameExists;
connection statement
{
command.Connection = connection;
command.CommandText =
@"SELECT TOP 1 0 " +
@"FROM [dbo].[products] p WITH (NOLOCK) " +
@"WHERE [p].[name] = @name";
command.Parameters.AddWithValue("name", name);
command.CommandTimeout = 100;
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
nameExists = reader.HasRows;
}
connection.Close();
}
How to increase my request to check the above conditions?
Note Please do not degrade this post, but post a comment if you think this post is not good mail. Also forgive me for my grammatical errors, if they are in my post.
user7601185