通过数据库导航 [英] navigata through database
本文介绍了通过数据库导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Helloo
我正在使用vb.net来构建Web应用程序
我有3个用于从数据库检索数据的文本框和4个拳头,上一个,下一个和最后一个按钮,可帮助我浏览表的记录.
但似乎我的代码不起作用.
我使用一个变量,procedualid来传递显示记录ID的文本框的值.
问题出在哪里?
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
推荐答案
嗨安纳,
也许您的Navigation子句中的sql字符串缺少&
试试这个并给出结果:
Sqll ="SELECT * FROM Person WHERE ID =''"&txt_id.value&"''"
代替这个
Sqll =选择*从人所在的ID =''txt_id.value''"
如果您不需要返回所有字段,则不应该选择* ...
希望这会有所帮助,
Vitor
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
这篇关于通过数据库导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文