Default parameters if textBox is empty
I have this to filter the table.
using (SqlConnection myDatabaseConnection = new
SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand mySqlCommand = new SqlCommand("Select *
from Employee WHERE EmpID >= @from AND EmpID <= @to",
myDatabaseConnection))
{
mySqlCommand.CommandType = CommandType.Text;
mySqlCommand.Parameters.AddWithValue("@from",
textBox1.Text);
mySqlCommand.Parameters.AddWithValue("@to",
textBox2.Text);
{
ds = new DataSet();
adapter = new SqlDataAdapter(mySqlCommand);
adapter.Fill(ds, "Employee");
}
}
}
For example I have 4001 in textBox1 and 4017 in texBox2. I gives me the
result of 4001,4002,4003 . . . 4017
The problem is for example I 4001 in textBox1 and none in textBox2 it
gives no result. How I will do it to have a result from 4001 until to the
last value of the table? And if the textBox1 is empty and textBox2 is 4017
, the result will be 1,2,3 up to 4017 assuming that 1 have the least
value?
No comments:
Post a Comment