1 string mySelectText = "SELECT * FROM Categories ORDER BY CategoryID";
2 string mySelectConn = "Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=northwind";
3 SqlDataAdapter myDataAdapter = new
SqlDataAdapter(mySelectText,mySelectConn);
4 myDataAdapter.InsertCommand.CommandText = "INSERT INTO
Categories(CategoryName, Description, Picture)
Values(@CategoryName,@Description,@Picture)";
5 myDataAdapter.InsertCommand.Connection = (SqlConnection)
myDataAdapter.SelectCommand.Connection;
这五句话是从MSDN中copy过来的,运行到第四句时出错Error: Object reference not set to an instance of an object.
2 string mySelectConn = "Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=northwind";
3 SqlDataAdapter myDataAdapter = new
SqlDataAdapter(mySelectText,mySelectConn);
4 myDataAdapter.InsertCommand.CommandText = "INSERT INTO
Categories(CategoryName, Description, Picture)
Values(@CategoryName,@Description,@Picture)";
5 myDataAdapter.InsertCommand.Connection = (SqlConnection)
myDataAdapter.SelectCommand.Connection;
这五句话是从MSDN中copy过来的,运行到第四句时出错Error: Object reference not set to an instance of an object.