Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据库数据加载到asp.net页面_Asp.net - Fatal编程技术网

将数据库数据加载到asp.net页面

将数据库数据加载到asp.net页面,asp.net,Asp.net,我想知道如何将数据库中的数据加载到asp.net表单中 因此,我使用代码通过查询“Select*From…Where…”获取数据 然后我把它加载到一个阅读器中 While (reader.read) { string sProductName = Convert.ToString(reader[1]); /* Now I need to display this name and all the other data (selling price, etc) on

我想知道如何将数据库中的数据加载到asp.net表单中

因此,我使用代码通过查询“
Select*From…Where…”获取数据

然后我把它加载到一个阅读器中

While (reader.read)
{   string sProductName = Convert.ToString(reader[1]);
    /*
    Now I need to display this name and all the other data 
    (selling price, etc) on the form
    But as I do not know how many products there will be it (the form) has to change 
    as the database information does (more products get added or removed). 
    */
}
我不知道最后一部分怎么做。如何使找到的数据显示在屏幕上

谢谢

我需要显示的数据是标题下的产品名称、产品说明和产品售价,这些名称仅此而已。

对于SQL数据库

使用id=“gridview1”获取gridview控件(您可以随意选择,但在代码中使用相同的id)

注意:

      While working with datareader sql connection must be open.

我使用文本框来显示值。您可以在任何需要的地方使用。dr[0]。ToString(),.dr[1]。ToString()……包含数据库表的值,根据您的要求。您可能必须具体说明数据是什么样的,以及您希望如何显示这些数据。是的,我尝试过谷歌搜索,但我只能获得您在源代码区域使用的代码@Venkat我遇到的问题是,我不能在form.load部分中使用

etc,因为它不接受它。我需要一些代码,允许我在form.load code部分输入html代码。您应该在表单和/p>元素上指定runat=“server”属性。稍后,您可以在服务器代码页上访问它。FindContol(IdOfYourElement)。嗨,好的,我想这会起作用我要试试谢谢谢谢,我不想在gridview中显示它,而只是逐行显示。您需要从数据库中获取值,还是从数据库中显示值我需要获取值,然后显示它们,您的代码可以工作,但我只想在reader[1]中显示信息,等等。谢谢,但我如何知道文本框的数量,因为随着新产品添加到数据库中,以及其他产品被删除,产品的数量将始终发生变化。如果有代码创建一个文本框或标签,那么我可以使用它。对不起,我不能理解你的实际问题。你能把你想要的代码放在图片中吗。我只是给你一个想法,你的疑问。
         SqlConnection sql= new SqlConnection("your data base connection");
        SqlCommand cmd = new SqlCommand("select * from your_table_name", sql);
        sql.open();
        SqlDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            Textbox1.Text=dr[0].ToString();
            Textbox2.Text=dr[1].ToString();
            Textbox3.Text=dr[2].ToString();
            ......................;

        }
      con.close();
      While working with datareader sql connection must be open.