How to Update user input into database??

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Public <span style="color:Blue; Class Form4
<span style="color:Blue; Dim con <span style="color:Blue; As <span style="color:Blue; New OleDb.OleDbConnection
<span style="color:Blue; Dim dbProvider <span style="color:Blue; As <span style="color:Blue; String
<span style="color:Blue; Dim dbSource <span style="color:Blue; As <span style="color:Blue; String
<span style="color:Blue; Dim ds <span style="color:Blue; As <span style="color:Blue; New DataSet
<span style="color:Blue; Dim da <span style="color:Blue; As OleDb.OleDbDataAdapter
<span style="color:Blue; Dim sql <span style="color:Blue; As <span style="color:Blue; String
<span style="color:Blue; Dim inc <span style="color:Blue; As <span style="color:Blue; Integer
<span style="color:Blue; Dim MaxRows <span style="color:Blue; As <span style="color:Blue; Integer

<span style="color:Blue; Private <span style="color:Blue; Sub Form4_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; MyBase.Load
dbProvider = <span style="color:#A31515; "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = <span style="color:#A31515; "Data Source = Lab4.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
Sql = <span style="color:#A31515; "SELECT * FROM weight"
da = <span style="color:Blue; New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, <span style="color:#A31515; "weight")
MsgBox(<span style="color:#A31515; "Record Is Ready", MsgBoxStyle.Information, <span style="color:#A31515; "DataBase Open")
inc = 1
MaxRows = ds.Tables(<span style="color:#A31515; "weight").Rows.<span style="color:Blue; Count
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub Button10_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button10.Click
<span style="color:Blue; If TextBox11.Text = <span style="color:#A31515; " " <span style="color:Blue; Or TextBox12.Text = <span style="color:#A31515; "" <span style="color:Blue; Or TextBox13.Text = <span style="color:#A31515; "" <span style="color:Blue; Or TextBox14.Text = <span style="color:#A31515; "" <span style="color:Blue; Or TextBox15.Text = <span style="color:#A31515; "" <span style="color:Blue; Or TextBox16.Text = <span style="color:#A31515; "" <span style="color:Blue; Or TextBox17.Text = <span style="color:#A31515; "" <span style="color:Blue; Or TextBox18.Text = <span style="color:#A31515; "" <span style="color:Blue; Or TextBox19.Text = <span style="color:#A31515; "" <span style="color:Blue; Then
MsgBox(<span style="color:#A31515; "Weight can not be null,Please enter all!", MessageBoxIcon.Warning)


<span style="color:Blue; ElseIf inc <> 1 <span style="color:Blue; Then
<span style="color:Blue; Dim cb <span style="color:Blue; As <span style="color:Blue; New OleDb.OleDbCommandBuilder(da)
<span style="color:Blue; Dim dsNewRow <span style="color:Blue; As DataRow
inc = 0
MaxRows = MaxRows + 1
dsNewRow = ds.Tables(<span style="color:#A31515; "weight").NewRow()

dsNewRow.Item(1) = TextBox11.Text
dsNewRow.Item(2) = TextBox12.Text
dsNewRow.Item(3) = TextBox13.Text
dsNewRow.Item(4) = TextBox14.Text
dsNewRow.Item(5) = TextBox15.Text
dsNewRow.Item(6) = TextBox16.Text
dsNewRow.Item(7) = TextBox17.Text
dsNewRow.Item(8) = TextBox18.Text
dsNewRow.Item(9) = TextBox19.Text

ds.Tables(<span style="color:#A31515; "weight").Rows.Add(dsNewRow)
da.Update(ds, <span style="color:#A31515; "weight")
MsgBox(<span style="color:#A31515; "New Record added to database")

<span style="color:Blue; Else
<span style="color:Blue; Me.Hide()
<span style="color:Blue; End <span style="color:Blue; If




<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
<br/>
This is my code..but i can update the database..someone can help solve this problem

View the full article
 
Back
Top