I am working on project which is connected to access DB.I am just concerned with coding it in vb.net.The db is already created by someone else.
The problem i have is
1)there is a primarykey in db which is "PAGENO" and it is set to text now i need it to autoincrement how do i do it.
2)when i delete a record in delete button click considering the pageno how do i rearrange the pageno field so that all the other code doesn't mess up
here's what i did
Private Sub Btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btndelete.Click
Dim cn As New OleDb.OleDbConnection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\administrator\My Documents\Visual Studio 2005\Projects\sample.mdb;Persist Security Info=False"
Dim cmd As New OleDb.OleDbCommand
Dim a As Integer
a = txtpage.Text
cmd.CommandText = "delete ti.[ti001],ti.[pageno],ti.[ti018],ti.[ti020],ti.[ti021],ti.[ti031],ti.[ti043],ti.[ti055],ti.[ti067],ti.[ti079],ti.[ti091],ti.[ti103],ti.[ti115],ti.[ti127],ti.[ti139],ti.[ti151],ti.[ti163],ti.[ti175],ti.[ti187],ti.[ti199],ti.[ti211],ti.[ti223] from ti where ti.pageno = '" & txtpage.Text & "'"
cmd.CommandType = CommandType.Text
cmd.Connection = cn
cn.Open()
cmd.ExecuteNonQuery()
Dim selectquery As String
Dim ds As New DataSet
Dim cm As New OleDb.OleDbCommand
txtpage.Text = a - 1
selectquery = "select TI.[ti021], ti.[ti001],ti.[ti031], ti.[ti043], ti.[ti055], ti.[ti067], ti.[ti079], ti.[ti091], ti.[ti103], ti.[ti115], ti.[ti127],ti.[ti139], ti.[ti151], ti.[ti163], ti.[ti175], ti.[ti187], ti.[ti199], ti.[ti211], ti.[ti223] from TI Where TI.[pageno]='" & txtpage.Text & "'"
Dim da As New OleDb.OleDbDataAdapter(selectquery, cn)
' cn.Open()
da.Fill(ds, "TI")
If ds.Tables(0).Rows.Count > 0 Then
TxtilID.Text = ds.Tables("TI").Rows(0).Item(0).ToString()
TextBox1.Text = ds.Tables("TI").Rows(0).Item(1).ToString()
txtepa1.Text = ds.Tables("TI").Rows(0).Item(2).ToString()
txtepa2.Text = ds.Tables("TI").Rows(0).Item(3).ToString()
txtepa3.Text = ds.Tables("TI").Rows(0).Item(4).ToString()
txtepa4.Text = ds.Tables("TI").Rows(0).Item(5).ToString()
txtepa5.Text = ds.Tables("TI").Rows(0).Item(6).ToString()
txtepa6.Text = ds.Tables("TI").Rows(0).Item(7).ToString()
txtepa7.Text = ds.Tables("TI").Rows(0).Item(8).ToString()
txtepa8.Text = ds.Tables("TI").Rows(0).Item(9).ToString()
txtIL1.Text = ds.Tables("TI").Rows(0).Item(10).ToString()
txtIL2.Text = ds.Tables("TI").Rows(0).Item(11).ToString()
txtIL3.Text = ds.Tables("TI").Rows(0).Item(12).ToString()
txtIL4.Text = ds.Tables("TI").Rows(0).Item(13).ToString()
txtIL5.Text = ds.Tables("TI").Rows(0).Item(14).ToString()
txtIL6.Text = ds.Tables("TI").Rows(0).Item(15).ToString()
txtIL7.Text = ds.Tables("TI").Rows(0).Item(16).ToString()
txtIL8.Text = ds.Tables("TI").Rows(0).Item(17).ToString()
ComboBox10.SelectedItem = ds.Tables("TI").Rows(0).Item(18).ToString()
Else
MsgBox("no more records", MsgBoxStyle.Information, "No Records")
End If
cn.Close()
End Sub
if this works fine by setting the txtpage.text to a integer variable 'a' before deleting the record ,button previous and next doesn't work
Private Sub Btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnnext.Click
Dim cn As New OleDb.OleDbConnection
Dim selectquery As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\administrator\My Documents\Visual Studio 2005\Projects\sample.mdb;Persist Security Info=False"
Dim ds As New DataSet
Dim cm As New OleDb.OleDbCommand
selectquery = "select TI.[ti021], ti.[ti001],ti.[ti031], ti.[ti043], ti.[ti055], ti.[ti067], ti.[ti079], ti.[ti091], ti.[ti103], ti.[ti115], ti.[ti127],ti.[ti139], ti.[ti151], ti.[ti163], ti.[ti175], ti.[ti187], ti.[ti199], ti.[ti211], ti.[ti223] from TI Where TI.[pageno]='" & (txtpage.Text) + 1 & "'"
Dim da As New OleDb.OleDbDataAdapter(selectquery, cn)
cn.Open()
da.Fill(ds, "TI")
If ds.Tables(0).Rows.Count > 0 Then
txtpage.Text = txtpage.Text + 1
TxtilID.Text = ds.Tables("TI").Rows(0).Item(0).ToString()
TextBox1.Text = ds.Tables("TI").Rows(0).Item(1).ToString()
txtepa1.Text = ds.Tables("TI").Rows(0).Item(2).ToString()
txtepa2.Text = ds.Tables("TI").Rows(0).Item(3).ToString()
txtepa3.Text = ds.Tables("TI").Rows(0).Item(4).ToString()
txtepa4.Text = ds.Tables("TI").Rows(0).Item(5).ToString()
txtepa5.Text = ds.Tables("TI").Rows(0).Item(6).ToString()
txtepa6.Text = ds.Tables("TI").Rows(0).Item(7).ToString()
txtepa7.Text = ds.Tables("TI").Rows(0).Item(8).ToString()
txtepa8.Text = ds.Tables("TI").Rows(0).Item(9).ToString()
txtIL1.Text = ds.Tables("TI").Rows(0).Item(10).ToString()
txtIL2.Text = ds.Tables("TI").Rows(0).Item(11).ToString()
txtIL3.Text = ds.Tables("TI").Rows(0).Item(12).ToString()
txtIL4.Text = ds.Tables("TI").Rows(0).Item(13).ToString()
txtIL5.Text = ds.Tables("TI").Rows(0).Item(14).ToString()
txtIL6.Text = ds.Tables("TI").Rows(0).Item(15).ToString()
txtIL7.Text = ds.Tables("TI").Rows(0).Item(16).ToString()
txtIL8.Text = ds.Tables("TI").Rows(0).Item(17).ToString()
ComboBox10.SelectedItem = ds.Tables("TI").Rows(0).Item(18).ToString()
ElseIf ds.Tables(0).Rows.Count = 0 Then
MsgBox("Your on last record", MsgBoxStyle.Information, "LAST RECORD")
End If
cn.Close()
End Sub
Private Sub Btnprvs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnprvs.Click
Dim cn As New OleDb.OleDbConnection
Dim selectquery As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\administrator\My Documents\Visual Studio 2005\Projects\sample.mdb;Persist Security Info=False"
Dim ds As New DataSet
Dim cm As New OleDb.OleDbCommand
selectquery = "select TI.[ti021], ti.[ti001],ti.[ti031], ti.[ti043], ti.[ti055], ti.[ti067], ti.[ti079], ti.[ti091], ti.[ti103], ti.[ti115], ti.[ti127],ti.[ti139], ti.[ti151], ti.[ti163], ti.[ti175], ti.[ti187], ti.[ti199], ti.[ti211], ti.[ti223] from TI Where TI.[pageno]='" & (txtpage.Text) - 1 & "'"
Dim da As New OleDb.OleDbDataAdapter(selectquery, cn)
cn.Open()
da.Fill(ds, "TI")
If ds.Tables(0).Rows.Count > 0 Then
txtpage.Text = txtpage.Text - 1
TxtilID.Text = ds.Tables("TI").Rows(0).Item(0).ToString()
TextBox1.Text = ds.Tables("TI").Rows(0).Item(1).ToString()
txtepa1.Text = ds.Tables("TI").Rows(0).Item(2).ToString()
txtepa2.Text = ds.Tables("TI").Rows(0).Item(3).ToString()
txtepa3.Text = ds.Tables("TI").Rows(0).Item(4).ToString()
txtepa4.Text = ds.Tables("TI").Rows(0).Item(5).ToString()
txtepa5.Text = ds.Tables("TI").Rows(0).Item(6).ToString()
txtepa6.Text = ds.Tables("TI").Rows(0).Item(7).ToString()
txtepa7.Text = ds.Tables("TI").Rows(0).Item(8).ToString()
txtepa8.Text = ds.Tables("TI").Rows(0).Item(9).ToString()
txtIL1.Text = ds.Tables("TI").Rows(0).Item(10).ToString()
txtIL2.Text = ds.Tables("TI").Rows(0).Item(11).ToString()
txtIL3.Text = ds.Tables("TI").Rows(0).Item(12).ToString()
txtIL4.Text = ds.Tables("TI").Rows(0).Item(13).ToString()
txtIL5.Text = ds.Tables("TI").Rows(0).Item(14).ToString()
txtIL6.Text = ds.Tables("TI").Rows(0).Item(15).ToString()
txtIL7.Text = ds.Tables("TI").Rows(0).Item(16).ToString()
txtIL8.Text = ds.Tables("TI").Rows(0).Item(17).ToString()
ComboBox10.SelectedItem = ds.Tables("TI").Rows(0).Item(18).ToString()
ElseIf ds.Tables(0).Rows.Count = 0 Then
MsgBox("Your on first record", MsgBoxStyle.Information, "FIRST RECORD")
End If
cn.Close()
End Sub
please help me with it.Thanks in advance.
This post has been edited by vibha9999: 29 October 2009 - 10:50 AM

Start a new topic
Add Reply





MultiQuote
| 


