主题:asp.net数据显示问题!
我现在的代码是能读取数据,但是如果去掉循环语句“While dbRead.Read()”和“End While”就会提示
没有找到列/行,但是有了循环语句,他会自动循环读取知道最后一条数据,等于每次显示的都是最后一
条数据,现在加了“Exit While”显示第一条数据后直接跳出循环。
请问:
1.第一段代码:如何直接显示第一条数据而不需要怎么麻烦的用循环语句!
还有2个页面如何传递信息,如以前:save.asp?id=1
另一个页面只需要:id=requset.form("id")就能实现!asp.net如何实现?
2.第二段代码:在data1数据显示空间中如何插入一列,
如:操作列,可以“删除”,“查看”,“修改”
第一段代码:
-------------------------------------------------------------------------------------
Dim myConnection As System.Data.OleDb.OleDbConnection
Dim myCommand As System.Data.OleDb.OleDbCommand
Dim dbRead As System.Data.OleDb.OleDbDataReader
Dim dbname As String
dbname = Server.MapPath("hk.mdb")
myConnection = New System.Data.OleDb.OleDbConnection
("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & dbname)
myConnection.Open()
myCommand = New System.Data.OleDb.OleDbCommand("select * FROM hk", myConnection)
dbRead = myCommand.ExecuteReader
While dbRead.Read()
ImageButton1.ImageUrl = "image/" & dbRead("yktu")
Image2.ImageUrl = "image/" & dbRead("fmtu")
bt.Text = dbRead("bt").ToString()
hc.Text = dbRead("hc").ToString()
zzr.Text = dbRead("zzr").ToString()
Exit While
End While
dbRead.Close()
myConnection.Close()
-------------------------------------------------------------------------------------
第二段代码
-------------------------------------------------------------------------------------
Dim myConnection As System.Data.OleDb.OleDbConnection
Dim myCommand As System.Data.OleDb.OleDbCommand
Dim dbRead As System.Data.OleDb.OleDbDataReader
Dim dbname As String
Dim id As Integer
id = Request.Form("id")
dbname = Server.MapPath("hk.mdb")
myConnection = New System.Data.OleDb.OleDbConnection
("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & dbname)
myConnection.Open()
myCommand = New System.Data.OleDb.OleDbCommand("select * FROM hk", myConnection)
Data1.DataSource = myCommand.ExecuteReader
Data1.DataBind()
dbRead.Close()
myConnection.Close()
[em10][em18][em10][em18]
没有找到列/行,但是有了循环语句,他会自动循环读取知道最后一条数据,等于每次显示的都是最后一
条数据,现在加了“Exit While”显示第一条数据后直接跳出循环。
请问:
1.第一段代码:如何直接显示第一条数据而不需要怎么麻烦的用循环语句!
还有2个页面如何传递信息,如以前:save.asp?id=1
另一个页面只需要:id=requset.form("id")就能实现!asp.net如何实现?
2.第二段代码:在data1数据显示空间中如何插入一列,
如:操作列,可以“删除”,“查看”,“修改”
第一段代码:
-------------------------------------------------------------------------------------
Dim myConnection As System.Data.OleDb.OleDbConnection
Dim myCommand As System.Data.OleDb.OleDbCommand
Dim dbRead As System.Data.OleDb.OleDbDataReader
Dim dbname As String
dbname = Server.MapPath("hk.mdb")
myConnection = New System.Data.OleDb.OleDbConnection
("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & dbname)
myConnection.Open()
myCommand = New System.Data.OleDb.OleDbCommand("select * FROM hk", myConnection)
dbRead = myCommand.ExecuteReader
While dbRead.Read()
ImageButton1.ImageUrl = "image/" & dbRead("yktu")
Image2.ImageUrl = "image/" & dbRead("fmtu")
bt.Text = dbRead("bt").ToString()
hc.Text = dbRead("hc").ToString()
zzr.Text = dbRead("zzr").ToString()
Exit While
End While
dbRead.Close()
myConnection.Close()
-------------------------------------------------------------------------------------
第二段代码
-------------------------------------------------------------------------------------
Dim myConnection As System.Data.OleDb.OleDbConnection
Dim myCommand As System.Data.OleDb.OleDbCommand
Dim dbRead As System.Data.OleDb.OleDbDataReader
Dim dbname As String
Dim id As Integer
id = Request.Form("id")
dbname = Server.MapPath("hk.mdb")
myConnection = New System.Data.OleDb.OleDbConnection
("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & dbname)
myConnection.Open()
myCommand = New System.Data.OleDb.OleDbCommand("select * FROM hk", myConnection)
Data1.DataSource = myCommand.ExecuteReader
Data1.DataBind()
dbRead.Close()
myConnection.Close()
[em10][em18][em10][em18]