Problem...incrementing

frisk

New member
Joined
Dec 9, 2004
Messages
1
Programming Experience
Beginner
Can somebody help a newbie please? This code is run when the user clicks a button on a form. It reads data from an SQLServer database into the dataset. It is displayed on the form where the user makes selections. The orders table just keeps an incrementing number that is used as an order number. These selections are then updated to one row of a table. Not too sure if the SQL command is allowed as is. The debugger stops at da.Update(ds, "Orders"). What is wrong with it please and thank you.



VB.NET:
' Open a database connection. 
Dim strConnection As String = "Data Source=xxx.x.x.xx;Initial Catalog=Test;USER ID=x;Password=x"
 
Dim cn As SqlConnection = New SqlConnection(strConnection)
 
cn.Open()
 
' Create a data adapter object and set its SELECT command.
 
Dim strSelect As String = "SELECT * FROM Orders; SELECT orderNo FROM orderNumber"
 
Dim da As SqlDataAdapter = New SqlDataAdapter(strSelect, cn)
 
Dim orderNoSelect As String = "SELECT orderNo FROM orderNumber"
 
Dim da1 As SqlDataAdapter = New SqlDataAdapter(orderNoSelect, cn)
 
 
 
' Set the data adapter object's UPDATE, INSERT, and DELETE
 
' commands. Use the SqlCommandBuilder class's ability to auto-
 
' generate these commands from the SELECT command.
 
Dim autogen As New SqlCommandBuilder(da)
 
' Load a data set.
 
Dim ds As DataSet = New DataSet
 
da.Fill(ds, "Orders")
 
da1.Fill(ds, "OrderNum")
 
' Get a reference to the DataTables.
 
Dim dt As DataTable = ds.Tables("Orders")
 
Dim dt1 As DataTable = ds.Tables("OrderNum")
 
 
 
' Modify the records.
 
Dim row As DataRow
 
row = dt.NewRow()
 
row.BeginEdit()
 
row("custName") = ComboBox1.SelectedValue 'OK
 
row("prodDesc") = ListBox1.SelectedValue 'Ok
 
row("quantity") = TextBox1.Text 'Ok
 
dt.Rows.Add(row)
 
row.EndEdit()
 
Dim drCurrent As DataRow
 
drCurrent = dt1.NewRow()
 
drCurrent.BeginEdit()
 
drCurrent("orderNo") = dt1.Rows.Count
 
dt1.Rows.Add(drCurrent) 
drCurrent.EndEdit()
 
' Update the database.
 
da.Update(ds, "Orders")
 
da1.Update(ds, "OrderNum")
 
' Close the database connection.
 
cn.Close()
 
 
 
TextBox1.Clear()
 
 
 
 
 
End Sub
 
Last edited:
Top Bottom