help me to update database

prav_roy

Well-known member
Joined
Sep 10, 2005
Messages
70
Location
Mumbai
Programming Experience
1-3
hi, i have been assigned a module, im using asp.net znd vb.net for that, the problem im facing is that i can not insert new row to database, im not using datagrid, i tried so many codes but not succeeded, plz helpme no.my code looks something like this



Dim
Dasend As OleDbDataAdapter = New OleDbDataAdapter(New OleDbCommand("select * from zeefaq", dbconn))
Dim comb As OleDbCommandBuilder = New OleDbCommandBuilder(Dasend)
Dim Dssend AsNew DataSet()
Dim Drsend As DataRow
Dim Dtsend As DataTable
Dim midi AsInteger
midi = cont + 1
dbconn.Open()
Dssend.Clear()
Dasend.TableMappings.Add("Tables", "zeefaq")
Dasend.FillSchema(Dssend, SchemaType.Source)
DataGrid1.DataSource = Dssend
DataGrid1.DataBind()
Drsend = Dssend.Tables("zeefaq").NewRow()
Drsend("msgid") = midi
Drsend("msgsub") = txtSub.Text
Drsend("name") = txtName.Text
Dssend.Tables("zeefaq").Rows.Add(Drsend)
Dasend.Update(Dssend, "zeefaq")
dbconn.Close()
 
Hello, if you are post information from textboxes this code always works for me in my VB code behind.

Try

Dim addSQL AsString = "INSERT INTO (enter your table name here )([Name],[BeginDate]) VALUES (" _
& " '" & textbox1.Text & "', " _
& " '" & textbox2.text & "' )"
'Check the connection state to make sure it is open
'I have my connection set as a global since it will always be the same.
'or you could set the connection at the top of try statement

If DBconn.State = ConnectionState.Closed Then
DBconn.Open()
EndIf

Dim InsertCMD As OleDb.OleDbCommand
InsertCMD =
New OleDb.OleDbCommand(addSQL, DBconn)
InsertCMD.ExecuteNonQuery()
MessageBox.Show("Update Completed!")

DBconn.close

Catch ex As Exception
MessageBox.Show(ex.Message)
exit function
EndTry

After placing the data in the database you will need to do a search in the database to fill your datagrid.

something like

Try

Dim findcmd AsString

FINDCMD = "SELECT * FROM "TABLE NAME" WHERE ID = " & lsDate

Dim findAdapter As System.Data.OleDb.OleDbDataAdapter = New OleDbDataAdapter(findcmd, DBconn)

If DBconn.State = ConnectionState.Closed Then
DBconn.Open()
EndIf

DS.Clear()
findAdapter.Fill(DS, "table Name")

objfrmMain.DataGrid3.SetDataBinding(DS, "Agenda")


objfrmMain.DataGrid3.ResetBindings()
DBconn.close

Catch ex As Exception

MessageBox.Show(ex.Message)
exit function

EndTry


Hope this helps

 
Back
Top