I have searched through the archive questions but can't find a suitable solution. I am sorry if one actually exists.
I am using Visual Studio 2013, .NET Runtime 4.5, MS-SQL 2008.
My code is simple:
public static class Global
{
public static DataTable CityTable;
}
To fill my data table I call:
SqlCommand SC1 = new SqlComman("SELECT DISTINCT City FROM Final WHERE City !='' AND City IS NOT null AND Published LIKE '%/%/" + DateTime.Now.ToString("yyyy") + "'", conn);
SqlDataAdapter SDA1 = new SqlDataAdapter(SC1);
SDA1.Fill(Golbal.CityTable);
Every time the call is made I get an error on the fill command. Error message as below:
System.ArgumentNullException : {"Value cannot be null.\r\nParameter name: dataTable"}
Can anyone help me to stop this exception?
Try assigning an empty table before using the table variable in SqlDataAdapter. Something as like,
SqlCommand SC1 = new SqlCommand("select distinct City from Final " +
"where City!='' and city is not null and " +
"Published like'%/%/" +
DateTime.Now.ToString("yyyy") + "'", conn);
SqlDataAdapter SDA1 = new SqlDataAdapter(SC1);
Global.CityTable = new DataTable();
SDA1.Fill(Global.CityTable);
Hope this helps...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With