Home › Forums › WinForms controls › Xceed Grid for WinForms › Not update to database after DatarowsChanged fired
-
AuthorPosts
-
#14530 |
Hi,
In my windows application, textbox for using entering store number (the parameter) and by clicking the button1, the data will be retrieved from database and displayed in a gridcontrol.I am using SqlCommandBuilder for generating insert and updating automatically, however, it doesn’t work so far.
The data is populated from select statement, and after I changed the data in a row, it fires DatarowsChanged event without error message, however, it doesn’t update to the database.
Please help with my commandbuilder! Thank you in advance.
————————————————————-Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conDWDb.Open()
Dim DBstrQ As New SqlCommand(“”, conDWDb)
DBstrQ.CommandText = “SELECT Bus_Date AS Bus_Date, Store_Num AS Store_Num, Z_Num_Transactions AS Z_Num_Transactions, Z_Net_Sales AS Z_Net_Sales, Z_Meal_Pack_Cnt, Z_Sales_Tax_Amt FROM micros.Operations where store_num=@storenum”
Dim adpSales As SqlDataAdapter = New SqlDataAdapter(DBstrQ)
adpSales.SelectCommand.Parameters.Add(“@StoreNum”, System.Data.SqlDbType.VarChar, 7)
adpSales.SelectCommand.Parameters(“@StoreNum”).Value = txtStoreNum.Textbuilder = New SqlCommandBuilder
builder.DataAdapter = adpSales
dsSales = New DataSet(“Operations”)
adpSales.Fill(dsSales, “Sales”)
Try
GridControl1.BeginInit() ‘ EndInit will be called later
GridControl1.DataSource = dsSales
GridControl1.DataMember = “Sales”
GridControl1.EndInit()
initialized = True
conDWDb.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
conDWDb.Close()
End Try
End SubPrivate Sub GridControl1_DatarowsChanged(ByVal senders As System.Object, ByVal e As System.EventArgs) Handles GridControl1.DataRowsChanged
If initialized Then
conDWDb.Open()
Dim DBstrQ As New SqlCommand(“”, conDWDb)
DBstrQ.CommandText = “SELECT Bus_Date AS Bus_Date, Store_Num AS Store_Num, Z_Num_Transactions AS Z_Num_Transactions, Z_Net_Sales AS Z_Net_Sales, Z_Meal_Pack_Cnt, Z_Sales_Tax_Amt FROM micros.Operations where store_num=@storenum”
Dim adpSales As SqlDataAdapter = New SqlDataAdapter(DBstrQ)
adpSales.SelectCommand.Parameters.Add(“@StoreNum”, System.Data.SqlDbType.VarChar, 7)
adpSales.SelectCommand.Parameters(“@StoreNum”).Value = txtStoreNum.Text
builder = New SqlCommandBuilder
adpSales.AcceptChangesDuringFill = False
builder = New SqlCommandBuilder(adpSales)
Try
Dim updateCommandSql As String = builder.GetUpdateCommand().CommandText
Catch err As Exception
End Try
Dim ds As DataSet = New DataSet
adpSales.Update(dsSales, “Sales”)
End If
conDWDb.Close()
End SubImported from legacy forums. Posted by JenHu (had 1908 views)
never mind, the parameters was set up, please ignore this posting.
Imported from legacy forums. Posted by JenHu (had 2931 views)
-
AuthorPosts
- You must be logged in to reply to this topic.