I'm using a class named Connection
.
Here is my class code:
public static string Username;
Then somewhere in my main windows form I'm searching in a datagridview and I use Connection.Username
.
I want to set in my SqlDataReader
do search
where Username = Connection.username
but only in case that this is not null.
Here is my main code:
SqlDataAdapter sda = new SqlDataAdapter("select UserName from CustomerTrans where UserName='"+Connection.Username+"'" , con);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.Rows.Clear();
foreach (DataRow item in dt.Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = item[0].ToString();
}
I want to avoid the case when Connection.Username
is null to return all results.