我在 c# 中连接了一个 sql 数据库,现在尝试将内容放入数据集中。我将如何做到这一点?
我的代码是:
string constr = "Data Source=ECEE;Initial Catalog=Internet_Bankaciligi;User ID=sa";
SqlConnection conn = new SqlConnection(constr);
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("Select * from Internet_Bankaciligi", conn);
DataSet myDataSet = new DataSet();
DataRow myDataRow;
SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);
mySqlDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
mySqlDataAdapter.Fill(myDataSet,"Internet_Bankaciligi");
myDataRow = myDataSet.Tables["IB_Account"].NewRow();
myDataRow["Account_ID"] = "NewID";
myDataRow["Branch_ID"] = "New Branch";
myDataRow["Amount"] = "New Amount";
myDataSet.Tables["Customers"].Rows.Add(myDataRow);
行:“mySqlDataAdapter.Fill(myDataSet,"Internet_Bankaciligi");" 给出错误“无效的对象名称'Internet_Bankaciligi'。” 但 Internet_Bankaciligi 是我的数据库名称。
另外,如果我使用:
SqlCommand selectCMD = new SqlCommand("select (*) from IB_Account", conn);
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.SelectCommand = selectCMD;
myAdapter.Fill(myDataSet);
然后:“SqlCommand selectCMD = new SqlCommand("select (*) from IB_Account", conn);" 给出一个错误,说明语法无效。我将如何正确处理?