第2部分开始显示表格感谢Wayne对第1部分的回答

编程入门 行业动态 更新时间:2024-10-28 13:18:37
本文介绍了第2部分开始显示表格感谢Wayne对第1部分的回答的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

特别感谢 现在,我要做的就是显示数据库中的表,这就是我尝试过的方法:

Special thanks to Now what I want to do is display the table in the database, this is what I have tried:

int DisplayTable() { using (SqlConnection myConnection2 = new SqlConnection(DBConn)) { SqlCommand MyCommand2 = new SqlCommand("SELECT * from TheTableName;", myConnection2); myConnection2.Open(); SqlDataReader reader = MyCommand2.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind(); return MyCommand2.ExecuteNonQuery(); } }

然后像以前一样放入按钮:

Then put in the button like I did before:

protected void btnDisplay_Click(object sender, EventArgs e) { DisplayTable(); }

but this does not work and gives the error: "Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition." What should I do?

特别感谢韦恩·盖拉德(Wayne Gaylard)对我的第一个问题的回答,如果您仍然在那里,请提供帮助. 在此先感谢...

Special thanks to Wayne Gaylard for the answer to my first question, if you are still out there please help. Thanks in advance...

推荐答案

答案在错误中: "DataSource和DataSourceID都在GridView1上定义.删除一个定义." 删除一个定义.猜测一下,检查您的Gridview定义,并取出DataSourceID分配,因为您在代码中设置了DataSource. The answer is in the error: "Both DataSource and DataSourceID are defined on ''GridView1''. Remove one definition." Remove one definition. At a guess, check your Gridview definition, and take out the DataSourceID assignment, since you are setting the DataSource in the code.

.aspx页面上的这一行自动放置在此处"DataSourceID ="SqlDataSource1"这是我删除的内容. 然后我得到一个关于仍然打开的阅读器的错误... 我的工作方式如下: This line on my .aspx page was put there automatically "DataSourceID="SqlDataSource1" Which is what I deleted. Then I got an error about the reader that was still opened... I got it work as follows: int DisplayTable() { using (SqlConnection myConnection2 = new SqlConnection(DBConn)) { SqlCommand MyCommand2 = new SqlCommand("SELECT * from TheTableName;", myConnection2); myConnection2.Open(); SqlDataReader reader = MyCommand2.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind(); reader.Close(); return MyCommand2.ExecuteNonQuery(); } }

作为一个刚开始编程的学生,我想感谢所有给我这么好的答案的人,这些答案适用于我的问题,只要有一种方法可以让他们知道我有多高兴.

As a student who has only just started programming, I would like to thank everyone who has given me such good answers that apply to my questions, if only there was a way I could let them know how gratefull I am.

更多推荐

第2部分开始显示表格感谢Wayne对第1部分的回答

本文发布于:2023-10-19 15:12:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1507901.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表格   Wayne

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!