I am connecting to an SQL server. I have a column which has date and time and another which has the user name. Once i connect to the database it shows everything except the null values in the column of date and time. I need to show only the column of data and time which holds null values and the user with the null value. How do i Display the null values but only the null values?
Below is my code:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sql_connection
{
class Program
{
static void Main(string[]args)
{
string conn=null;
SqlConnection connection;
conn=("Data Source=Database\\SQL2012;Initial Catalog=Table;User ID=user;Password=example");
connection=new SqlConnection(conn);
try{
connection.Open();
Console.Writeline("Connection Open!");
SqlCommand cmd= new SqlCommand("SELECT tabledateandtime,tableuser FROM [dbo].[tb_Showingnull]");
cmd.Connection = connection;
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
Console.WriteLine("{1} , {0}", reader["tabledateandtime"].ToString(), reader["tableuser"].ToString()));
}
connection.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
SqlCommand cmd= new SqlCommand("SELECT tabledateandtime,tableuser FROM [dbo].[tb_Showingnull]");toSqlCommand cmd= new SqlCommand("SELECT tabledateandtime,tableuser FROM [dbo].[tb_Showingnull] WHERE tabledateandtime IS NULL OR tableuser IS NULL");