Hi, I had a problem on updating from textboxes to db. From the beginning iof the system, it will retreive data from datbase and display in the datagrid. Once the update push button is click, it will display in a form where form contain textboxes.
Textboxes are displaying the data once the oush button is clicked. When i click "save changes" button in the form, it will auto update to the db. But it can't work. Here are the codes:
Dim cnn AsNew OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Inetpub\wwwroot\button\movie.mdb")
Dim strSQL AsString = "Update movieDet SET Title = @Title, price = '" + Price.Text + "' WHERE Title = @Title "
Dim cmd2 AsNew OleDbCommand(strSQL, cnn)
With cmd2.Parameters
.Add(New OleDbParameter("@MovieID", _
OleDbType.Integer)).Value = _
CInt(update.DataKeys(update.SelectedIndex).ToString)
.Add(New OleDbParameter("@Title", _
OleDbType.VarChar, 40)).Value = txtTitle.Text
.Add(New OleDbParameter("@price", _
OleDbType.Currency)).Value = CDbl(Price.Text)
EndWith
Try
cnn.Open()
cmd2.ExecuteNonQuery()
Response.Write("Product successfully saved to the database.")
pnlForm.Visible = False
Catch exp As Exception
Response.Write("Error: " & exp.Message)
Finally
cnn.Close()
EndTry
The only prob is it can't update the existing data in the db. Help pls!
I had another qns. If i had a checkboxlist in a webform and i had three items in the checkboxlist. Namely:"abc", "def", "ghi". If two among the three had been checkedit saved in the db like this:
row1: abc
row2:ghi
Here are the codes:
Dim i As Integer = tb_num.Text
Dim a As Integer
For a = 1 To i
Dim cmd As New OleDbCommand("INSERT INTO roomDet ([branch]) VALUES('" & CheckBoxList1.SelectedValue & "')", New OleDbConnection(strConn))
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
Next
How to imrove this codes to the requirement i want? thnkx
Rdgs,
tiffany
Textboxes are displaying the data once the oush button is clicked. When i click "save changes" button in the form, it will auto update to the db. But it can't work. Here are the codes:
Dim cnn AsNew OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Inetpub\wwwroot\button\movie.mdb")
Dim strSQL AsString = "Update movieDet SET Title = @Title, price = '" + Price.Text + "' WHERE Title = @Title "
Dim cmd2 AsNew OleDbCommand(strSQL, cnn)
With cmd2.Parameters
.Add(New OleDbParameter("@MovieID", _
OleDbType.Integer)).Value = _
CInt(update.DataKeys(update.SelectedIndex).ToString)
.Add(New OleDbParameter("@Title", _
OleDbType.VarChar, 40)).Value = txtTitle.Text
.Add(New OleDbParameter("@price", _
OleDbType.Currency)).Value = CDbl(Price.Text)
EndWith
Try
cnn.Open()
cmd2.ExecuteNonQuery()
Response.Write("Product successfully saved to the database.")
pnlForm.Visible = False
Catch exp As Exception
Response.Write("Error: " & exp.Message)
Finally
cnn.Close()
EndTry
The only prob is it can't update the existing data in the db. Help pls!
I had another qns. If i had a checkboxlist in a webform and i had three items in the checkboxlist. Namely:"abc", "def", "ghi". If two among the three had been checkedit saved in the db like this:
row1: abc
row2:ghi
Here are the codes:
Dim i As Integer = tb_num.Text
Dim a As Integer
For a = 1 To i
Dim cmd As New OleDbCommand("INSERT INTO roomDet ([branch]) VALUES('" & CheckBoxList1.SelectedValue & "')", New OleDbConnection(strConn))
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
Next
How to imrove this codes to the requirement i want? thnkx
Rdgs,
tiffany
Last edited: