I have this example code:
string query = "select * from xy where id == @id and name == @name";
SqlCommand cmd = new SqlCommand(query);
if(txtUsername.Text.Length > 0)
{
cmd.Parameters.Add["@name", SqlDbType.VarChar);
cmd.Parameters["@name"].Value = txtUsername.Text;
}
Now if the txtUsername <=0 I have to cut the query string dropping the AND and the name == @name. How can I achieve this result?
Thanks in advance.
.Length
?