Regarding UpDatE STateMent ????

elf

Active member
Joined
Jun 4, 2003
Messages
37
i was trying to update information to my database with datagrid using vb.net..i run the program and it runs BUT the bad thing is that although it runs...the information is not being updated...the worse thing is that becoz it doesnt show any error so i dun knoe wat to do??? Can anyone help mi??? The source code i use is below:


SOURCE CODE
------------------------------------------------------------------------------------
Dim conn As System.Data.OleDb.OleDbConnection
Dim MyCommand As System.Data.OleDb.OleDbCommand

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Data Source=C:\Inetpub" & _
"\wwwroot\tempdb.mdb;Mode=ReadWrite|Share Deny

Dim txtTS1 As TextBox = e.Item.Cells(6).Controls(0)
Dim txtTS2 As TextBox = e.Item.Cells(7).Controls(0)
Dim txtTS3 As TextBox = e.Item.Cells(8).Controls(0)
Dim txtTS4 As TextBox = e.Item.Cells(9).Controls(0)
Dim txtTS5 As TextBox = e.Item.Cells(10).Controls(0)
Dim txtTS6 As TextBox = e.Item.Cells(11).Controls(0)
Dim txtTS7 As TextBox = e.Item.Cells(12).Controls(0)
Dim txtTS8 As TextBox = e.Item.Cells(13).Controls(0)
Dim strUpdateStmt As String

strUpdateStmt = " UPDATE Timetable SET" & " TS1 =@C1, TS2 =@C2, TS3 = @C3 ,TS4 =@C4, TS5 =@C5 ,TS6 =@C6, TS7 =@C7, TS8 =@C8, TS9 =@C9 ,TS10 =@C10"
conn = New System.Data.OleDb.OleDbConnection(strConn)
MyCommand = New System.Data.OleDb.OleDbCommand(strUpdateStmt, conn)
MyCommand.Parameters.Add(New OleDb.OleDbParameter("@C1", txtTS1.Text))
MyCommand.Parameters.Add(New OleDb.OleDbParameter("@C2", txtTS2.Text))
MyCommand.Parameters.Add(New OleDb.OleDbParameter("@C3", txtTS3.Text))
MyCommand.Parameters.Add(New OleDb.OleDbParameter("@C4", txtTS4.Text))
MyCommand.Parameters.Add(New OleDb.OleDbParameter("@C5", txtTS5.Text))
MyCommand.Parameters.Add(New OleDb.OleDbParameter("@C6", txtTS6.Text))
MyCommand.Parameters.Add(New OleDb.OleDbParameter("@C7", txtTS7.Text))
MyCommand.Parameters.Add(New OleDb.OleDbParameter("@C8", txtTS8.Text))
MyCommand.Parameters.Add(New OleDb.OleDbParameter("@ID", e.Item.Cells(1).Text))
conn.Open()


MyCommand.ExecuteNonQuery()
DataGrid1.EditItemIndex = -1
conn.Close()
BindData()

End Sub



Sub BindData()

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Data Source=C:\Inetpub" & _
"\wwwroot\tempdb.mdb;Mode=ReadWrite|Share Deny

Dim oledb As String = "Select id, TS1, TS2, TS3, TS4, TS5, TS6, TS7, TS8, TS9 from Timetable"
Dim conn As New System.Data.OleDb.OleDbConnection(strConn)
Dim objDR As OleDb.OleDbDataReader
Dim Cmd As New System.Data.OleDb.OleDbCommand(oledb, conn)
conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
DataGrid1.DataSource = objDR
DataGrid1.DataBind()
conn.Close()

End Sub
 
Back
Top