Adding new Rows to the Data base table
-
Hi Can any one please tell me how to add the new rows to the existing table with the values using SqlAdapter and Data Row with out using insert statement. DataSet dset = new DataSet("DBTable"); DataTable dbtable = new DataTable("DBTable"); dset.Tables.Add(dbtable); SqlCommand dbcommand = new SqlCommand(); dbcommand.CommandText ="select * from DBTable"; dbcommand.Connection = myConnection; SqlDataAdapter dbDA = new SqlDataAdapter(dbcommand); dbDA.TableMappings.Add("Table", "DBTable"); dbDA.Fill(dset, "DBTable"); DataRow row; row = dbtable.NewRow(); row["FileName"] = DBfile; row["Meters"] = IMeter; dbtable.Rows.Add(row); dbDA.Update(dset); This above code throws exception called "Update requires a valid InsertCommand when passed DataRow collection with new rows." any Idea?
-
Hi Can any one please tell me how to add the new rows to the existing table with the values using SqlAdapter and Data Row with out using insert statement. DataSet dset = new DataSet("DBTable"); DataTable dbtable = new DataTable("DBTable"); dset.Tables.Add(dbtable); SqlCommand dbcommand = new SqlCommand(); dbcommand.CommandText ="select * from DBTable"; dbcommand.Connection = myConnection; SqlDataAdapter dbDA = new SqlDataAdapter(dbcommand); dbDA.TableMappings.Add("Table", "DBTable"); dbDA.Fill(dset, "DBTable"); DataRow row; row = dbtable.NewRow(); row["FileName"] = DBfile; row["Meters"] = IMeter; dbtable.Rows.Add(row); dbDA.Update(dset); This above code throws exception called "Update requires a valid InsertCommand when passed DataRow collection with new rows." any Idea?
You need to add a SqlCommand for INSERT to the SqlDataAdapter (you have already done so for SELECT, but passing it to the constructor).**
xacc.ide-0.1.3.14 - Now with syntax support for PowerShell
xacc.ide-0.1.3.13 source code**
-
You need to add a SqlCommand for INSERT to the SqlDataAdapter (you have already done so for SELECT, but passing it to the constructor).**
xacc.ide-0.1.3.14 - Now with syntax support for PowerShell
xacc.ide-0.1.3.13 source code**
-
if u want to update db with dataadapters update method then u have to define adapters insert command with proper parameters. rahul
You should be replying to the original person asking the question :)**
xacc.ide-0.1.3.14 - Now with syntax support for PowerShell
xacc.ide-0.1.3.13 source code**