如何在其他Web表单中访问数据库信息? [英] how do i access database information in a different webform?
本文介绍了如何在其他Web表单中访问数据库信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将某些数据字段从一种Web表单传输到另一种Web表单.我无法正确执行此操作.我正在使用会话进行传输,但是仍然会出错.
请帮忙,因为我刚刚开始学习ASP.net.
文件Default5.aspx.vb包含:
I need to transfer certain data fields from one webform to another. I am not able to do this correctly. I am making use of sessions for transfer but its still giving error.
Please help since i have just started learning ASP.net.
File Default5.aspx.vb contains:
Imports System.Data
Imports System.Data.OleDb
Partial Class Default5
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
fillgrid()
End If
End Sub
Public Sub fillgrid()
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=A:\anu\Project\WebSite4\WebSite4\App_Data\prd_dell.accdb")
Dim da As New OleDbDataAdapter("select * from prd_dell", con)
Dim ds As New DataSet
da.Fill(ds, "prd_dell")
GridView1.DataSource = ds.Tables("prd_dell")
GridView1.DataBind()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cc As CheckBox
Dim str As String = ""
Dim i As Integer
For i = 0 To GridView1.Rows.Count - 1
cc = CType(GridView1.Rows(i).Cells(0).FindControl("c1"), CheckBox)
If cc.Checked = True Then
str = str & GridView1.Rows(i).Cells(0).Text & " " & GridView1.Rows(i).Cells(1).Text & " " & GridView1.Rows(i).Cells(2).Text & " - " & GridView1.Rows(i).Cells(3).Text & " " & GridView1.Rows(i).Cells(4).Text & "<br>"
Label2.Text = GridView1.Rows(i).Cells(4).Text
Label3.Text = GridView1.Rows(i).Cells(0).Text
End If
Next
Session("pid") = Label3.Text
Session("prc") = Label2.Text
Context.Items.Add("mydata", str)
Server.Transfer("default6.aspx")
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
End Class
and Default6.aspx.vb contains:
Imports System.Data
Imports System.Data.OleDb
Partial Class Default6
Inherits System.Web.UI.Page
Dim qt As Integer
Dim pr As Integer
Dim pid As Integer
Dim tot As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
qt = TextBox1.Text
pid = Session("pid")
pr = Session("prc")
tot = qt * pr
Label4.Text = tot
Response.Write(Context.Items("mydata") + "<br />")
End Sub
Protected Sub GridView3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView3.SelectedIndexChanged
Dim ds As DataSet
ds = CType(Session("mydata"), DataSet)
If ds Is Nothing Then
ds = New DataSet
Dim dt As New DataTable("bill")
dt.Columns.Add("prd_id", System.Type.GetType("System.Int32"))
dt.Columns.Add("qty", System.Type.GetType("System.Int32"))
dt.Columns.Add("price", System.Type.GetType("System.Int32"))
dt.Columns.Add("total", System.Type.GetType("System.Int32"), "price*qty")
ds.Tables.Add(dt)
End If
pid = Convert.ToInt32(GridView3.SelectedRow.Cells(0).Text)
pr = Convert.ToInt32(GridView3.SelectedRow.Cells(4).Text)
'Dim tt As TextBox
'tt = CType(GridView3.SelectedRow.FindControl("TextBox1"), TextBox)
qt = Convert.ToInt32(TextBox1.Text)
tot = qt * pr
Response.Write(pid & " " & qt & " " & pr)
Dim r As DataRow
r = ds.Tables("bill").NewRow
r("prd_id") = pid
r("qty") = qt
r("price") = pr
r("total") = tot
ds.Tables("bill").Rows.Add(r)
Session("mydata") = ds
End Sub
End Class
-------------------------------------------------- ----------------------------------
我在第二个文件中遇到错误.请指南
------------------------------------------------------------------------------------
I am getting an error in the 2nd file. please guide
推荐答案
由于您给出的行为信息很少,例如错误或正在发生的事情,我将开始阅读本文 ^ ]
As you have given little behaviour information such as errors or what is happening, I would start having a read of this article How to: Pass Values Between ASP.NET Web Pages[^]
这篇关于如何在其他Web表单中访问数据库信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文