I want to select rows from my SQL Server table (it has 3 columns) and to display them into my Datagridview. My problem about null values. How can I pass null values? (Sometimes the first column and the second column are empty.
).
Below is my code:
string cm = "SELECT column1, column2, column3 FROM mytablename WHERE column1='"
+ sIS[mSI] + "' AND column2='" + sR[mSSI] + "' OR column1='" + sR[mSSI]
+ "' AND column2='" + sIS[mSI] + "'";
Note: I edited my code.
You should be using parameters to pass values into a SQL statement or else you will be vulnerable to SQL injection attacks. You can create a
SqlCommandobject, createSqlParameterobjects, then set values on them. If any of your values are null, then you can passDBNull.Valueas the parameter value.