Click here to Skip to main content
15,891,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Helloo
I am using vb.net to build a web app
I have 3 text boxes that retrieve data from the database and 4 buttons fist, previous, next and last that help me to navigate through the records of the table.
But it seems that my code doesnt work.
i use a variable, actualid to pass the value of the textbox where the id of the record is shown.
where is the problem?
VB
Imports System.Data.OleDb

Imports System.Data.SqlClient
  

Public Class default

    Inherits System.Web.UI.Page

    Dim Sqll As String

 

    Dim dst As New DataSet

    Dim MaxRows As Integer

    Dim SQLConnection As Object

    Dim uid As Integer

    Dim da As OleDb.OleDbDataAdapter

    Dim cmd As SqlCommand

    Dim conn As New OleDb.OleDbConnection

    Dim actualid As Integer = Convert.ToInt32(txt_id.Value)

  

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Navigate(actualid)

    End Sub

        Private Sub Navigate(int As Integer)

 

        Dim actualid As Integer = Convert.ToInt32(txt_id.Value)

        Dim conn As New OleDb.OleDbConnection

        Dim strConn As String = "Provider=SQLOLEDB; Data Source=; Initial Catalog=; User ID=; Password="

        conn.ConnectionString = strConn

 

        conn.Open()

        Dim dst As New DataSet

        Dim da As OleDb.OleDbDataAdapter

        Sqll = "SELECT * FROM Person WHERE Id ='txt_id.value'"

        da = New OleDb.OleDbDataAdapter(Sqll, conn)

        da.Fill(dst, "Person")

        Max = dst.Tables("Customer").Rows.Count

        txt_name.Value = ds.Tables("Person").Rows(inc).Item("2")

        txt_surname.Value = ds.Tables("Person").Rows(inc).Item("3")

        txt_city.Value = ds.Tables("Person").Rows(inc).Item("4")

txt_id.Value = dst.Tables("Person").Rows(int).Item("Id")

conn.close()

    End Sub

    Protected Sub btn_next_Click(sender As Object, e As EventArgs) Handles btn_next.Click

        If actualid <> MaxRows Then
            actualid = actualid + 1

            Navigate(actualid)

        End If

    End Sub

 

 
    Protected Sub btn_first_Click(sender As Object, e As EventArgs) Handles btn_first.Click

        If (actualid <> 0) Then

            actualid = 0

            Navigate(actualid)

        End If

    End Sub

 
    Protected Sub btn_previews_Click(sender As Object, e As EventArgs) Handles btn_previews.Click

        If (actualid > 0) Then

            actualid = actualid - 1

            Navigate(actualid)

        End If

    End Sub

    Protected Sub btn_last_Click(sender As Object, e As EventArgs) Handles btn_last.Click

        If (actualid <> (MaxRows - 1)) Then

            actualid = MaxRows - 1

 
            Navigate(actualid)


        End If

    End Sub
Posted
v2

1 solution

hi Annnaa,

maybe your sql string inside the navigate sub is missing the &


Try this and give the result :

Sqll = "SELECT * FROM Person WHERE Id ='"& txt_id.value &"'"

instead of this

Sqll = "SELECT * FROM Person WHERE Id ='txt_id.value'"

and u shouldn't do select * if u don't need all the fields to be returned...

Hope this helps,
Vitor
 
Share this answer
 
v3
Comments
lovitaxxxx 22-Nov-12 9:34am    
running app shows me this error:
Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 21: Dim conn As New OleDb.OleDbConnection
Line 22: Dim idaktuale As Integer = Convert.ToInt32(txt_id.Value)


How can i pass a textbox value to a variable?
is the sintax correct?
lovitaxxxx 22-Nov-12 9:36am    
I think that the problem of this code consist that in the next button click event, the variable actualid does not increment.. maintain the same value always :/
I dont know how to fix this
_Vitor Garcia_ 22-Nov-12 9:47am    
One other thing that comes to me mind is that inthe navigate sub you have a parameter which you are not using

Inside the navigate, isn't this what u want ?

Sqll = "SELECT * FROM Person WHERE Id ='"& int.tostring &"'"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900