如何将数据从Access数据库添加到VISUAL WEB DEVELOPER中的datagrid视图 [英] How to add data from access database to datagrid view in VISUAL WEB DEVELOPER

查看:86
本文介绍了如何将数据从Access数据库添加到VISUAL WEB DEVELOPER中的datagrid视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用可视化Web开发人员来设计基于Web的应用程序。

当我尝试将数据从access数据库添加到datagrid视图时,它显示错误,添加id而不是系统成员....

错误屁股跟随



错误1''添加''不是''System.Web的成员。 UI.WebControls.GridViewRowCollection''。



我的代码是:---



 受保护的  Sub  btnClick_Click( ByVal  sender 作为 对象 ByVal  e  As  EventArgs)句柄 btnClick.Click 
Dim con As OleDb.OleDbConnection
con = Db_Con()
Dim cmd 作为 OleDb.OleDbCommand
cmd = OleDb.OleDbCommand ( SELECT Employee_Details。[Given name] FROM Employee_Details,con)
Dim dr As OleDb.OleDbDataReader

dr = cmd.ExecuteReader
如果(dr.Read()= False 那么
MsgBox( 无法找到记录,vbOKOnly)
< span class =code-keyword> Else
Dim i As < span class =code-keyword>整数 = 0
昏暗 qry As String = SELECT Employee_Details。[given name] FROM Employee_Details
Dim da As OleDb.OleDbDataAdapter = OleDb.OleDbDataAdapter(qry,con)
Dim ds As DataSet = DataSet
da.Fill(ds, Employee_Details
Dim dt As DataTable = ds.Tables( Employee_Details
Dim dr1 As DataRow
对于 每个 dr1 dt.Rows
dgvEmployee.Rows中。 add()
' 此添加的问题,同时向datagrid视图添加数据...显示add不是系统的成员

dgvemployee.item( 0 ,i).value = dr1( Employee_Details
' 它还显示了dgvemployees.item,该项目不是系统的成员
i + = 1

下一步
结束 如果
结束 Sub





辩诉se help

解决方案

dgvEmployee.Rows.add()

执行不正确。您正在尝试 Winforms方式 [ ^ ]这里与web不同。



您可以使用Rows.Add作为网格源表。类似于:

 DataTable dt =  new  DataTable(); 
dt.Columns.Add( new System.Data.DataColumn( TextBox1Column typeof String )));
DataRow博士;
dr = dt.NewRow();
dr [ 0 ] = TextBox1.Text;
dt.Rows.Add(dr);



根据需要修改。


hii i am using visual web developer to design a web based application.
when i tried to add data from access database to datagrid view , its showing an error that add id not a member of system....
the error ass follows

Error 1 ''add'' is not a member of ''System.Web.UI.WebControls.GridViewRowCollection''.

my code is:---

    Protected Sub btnClick_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClick.Click
        Dim con As OleDb.OleDbConnection
        con = Db_Con()
        Dim cmd As OleDb.OleDbCommand
        cmd = New OleDb.OleDbCommand("SELECT Employee_Details.[Given name] FROM Employee_Details", con)
        Dim dr As OleDb.OleDbDataReader

        dr = cmd.ExecuteReader
        If (dr.Read() = False) Then
            MsgBox("Failed to find the records", vbOKOnly)
        Else
            Dim i As Integer = 0
            Dim qry As String = "SELECT Employee_Details.[Given name] FROM Employee_Details"
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(qry, con)
            Dim ds As DataSet = New DataSet
            da.Fill(ds, "Employee_Details")
            Dim dt As DataTable = ds.Tables("Employee_Details")
            Dim dr1 As DataRow
            For Each dr1 In dt.Rows
                dgvEmployee.Rows.add()
' the problem with this add, while adding data to the datagrid view... its showing add is not a member of system

                dgvemployee.item(0, i).value = dr1("Employee_Details") 
' Also its showing the dgvemployees.item,   the item is not a member of system 
                i += 1

            Next
        End If
    End Sub



Please help

解决方案

dgvEmployee.Rows.add()
Incorrect implementation. You are trying Winforms way[^] here which is not same for web.

You can use Rows.Add to table that is source of grid. Something like:

DataTable dt = new DataTable();
dt.Columns.Add(new System.Data.DataColumn("TextBox1Column", typeof(String)));
DataRow dr; 
dr = dt.NewRow();
dr[0] = TextBox1.Text;
dt.Rows.Add(dr);


Modify as per your need.


这篇关于如何将数据从Access数据库添加到VISUAL WEB DEVELOPER中的datagrid视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆