T
tomp
Hi,
I am trying to insert a row into the Categories Table in
Nothwinds database in MSDE. I am able to manually insert
it using a query tool.
Using the Debugger, it appears the DataSet loads
correctly, the Data Row is populated correctly, and the
new row is added to the DataSet. But the database is not
updated. What am I missing?
Thanks in advance,
Tom
======
Sub Main()
Dim nwindConn As SqlConnection = New SqlConnection
("Data Source=COL-TP5170-LT1\VSdotNET;Integrated
Security=SSPI;Initial Catalog=Northwind;")
Dim nwindDA As SqlDataAdapter = New SqlDataAdapter
("SELECT CategoryID, CategoryName, Description FROM
Categories", nwindConn)
nwindConn.Open()
Dim SqlInsertCommand1 As SqlCommand = New SqlCommand()
SqlInsertCommand1.CommandText = "INSERT INTO Categories
(CategoryName, Description) VALUES (@CategoryName,
@Description)"
SqlInsertCommand1.Connection = nwindConn
SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CategoryName",
System.Data.SqlDbType.NVarChar, 15, "CategoryName"))
SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Description",
System.Data.SqlDbType.NVarChar, 1073741823, "Description"))
Dim nwindDS As DataSet = New DataSet()
nwindDA.Fill(nwindDS, "Categories")
Dim dtTable As DataTable
Dim drRow As DataRow
dtTable = nwindDS.Tables("Categories")
drRow = dtTable.NewRow()
drRow("CategoryName") = "New Category Name"
drRow("Description") = "New Description"
dtTable.Rows.Add(drRow)
nwindDS.AcceptChanges()
nwindDA.Update(nwindDS, "Categories")
nwindConn.Close()
End Sub
I am trying to insert a row into the Categories Table in
Nothwinds database in MSDE. I am able to manually insert
it using a query tool.
Using the Debugger, it appears the DataSet loads
correctly, the Data Row is populated correctly, and the
new row is added to the DataSet. But the database is not
updated. What am I missing?
Thanks in advance,
Tom
======
Sub Main()
Dim nwindConn As SqlConnection = New SqlConnection
("Data Source=COL-TP5170-LT1\VSdotNET;Integrated
Security=SSPI;Initial Catalog=Northwind;")
Dim nwindDA As SqlDataAdapter = New SqlDataAdapter
("SELECT CategoryID, CategoryName, Description FROM
Categories", nwindConn)
nwindConn.Open()
Dim SqlInsertCommand1 As SqlCommand = New SqlCommand()
SqlInsertCommand1.CommandText = "INSERT INTO Categories
(CategoryName, Description) VALUES (@CategoryName,
@Description)"
SqlInsertCommand1.Connection = nwindConn
SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CategoryName",
System.Data.SqlDbType.NVarChar, 15, "CategoryName"))
SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Description",
System.Data.SqlDbType.NVarChar, 1073741823, "Description"))
Dim nwindDS As DataSet = New DataSet()
nwindDA.Fill(nwindDS, "Categories")
Dim dtTable As DataTable
Dim drRow As DataRow
dtTable = nwindDS.Tables("Categories")
drRow = dtTable.NewRow()
drRow("CategoryName") = "New Category Name"
drRow("Description") = "New Description"
dtTable.Rows.Add(drRow)
nwindDS.AcceptChanges()
nwindDA.Update(nwindDS, "Categories")
nwindConn.Close()
End Sub