This question already has an answer here:
string sel = "select * from PUTIN";
DataSet ds = new DataSet();
DataTable dt = ds.Tables["put"];
DataRow row = dt.NewRow();
This is the code. When I run the line DataRow row = dt.NewRow();
I get an exception:
Object reference not set to an instance of an object
I find dt
is null, why and how to slove it?
Your
DataSet
is empty currently. You need to use aSqlDataAdapter
here to fill yourDataSet
. Like this: