如何从数据集中读取所有数据并在表单视图中显示 [英] How to read all data from dataset and display in form view

查看:88
本文介绍了如何从数据集中读取所有数据并在表单视图中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




以下命令将只显示表格中的一条记录

我要显示的所有记录是什么???????? ???



Hi
The following command will display only one record in a form
What do all of my records to display??????????

string con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mobile.mdf;Integrated Security=True;User Instance=True";
        SqlConnection sqlcon = new SqlConnection();
        sqlcon.ConnectionString = con;
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = sqlcon;
        cmd.CommandText = "StoredProcedure1";
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet dta = new DataSet();
            da.Fill(dta);
        try
        {
            sqlcon.Open();
            FormView1.DataSource = dta;
                FormView1.DataBind();
            sqlcon.Close();
        }
        catch
        {
            //
        }





代码商店程序





code store procedure

ALTER PROCEDURE dbo.StoredProcedure1
as
begin
select * from tproduct
end;

推荐答案

Hello Farhad,



根据微软

FormView控件用于显示表中数据源的单个记录。使用FormView控件时,指定模板以显示和编辑绑定值。模板包含格式,控件和绑定表达式以创建形式。 FormView控件通常与GridView控件结合使用,用于主/详细方案。本节包含有关FormView控件的以下主题。

参考 FormView Web服务器控件 [ ^ ]



解决方案您的要求请使用DataList,Repeater或Gridview显示所有记录,然后单击编辑按钮,您可以使用FormView更新或选择记录。
Hello Farhad,

As per microsoft
"The FormView control is used to display a single record from a data source in a table. When using the FormView control, you specify templates to display and edit bound values. The templates contain formatting, controls, and binding expressions to create the form. The FormView control is often used in combination with a GridView control for master/detail scenarios. This section contains the following topics about the FormView control."
Reference: FormView Web Server Control [^]

Solution of your requirement please use DataList, Repeater or Gridview to show all records and click on Edit button you can use FormView to Update or selected records.


这篇关于如何从数据集中读取所有数据并在表单视图中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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