Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
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?
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 22-Nov-12 3:10am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v3
Comments
Annnaa at 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?
Annnaa at 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
VitorHugoGarcia at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100