本文介绍了第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...
推荐答案
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部分的回答的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!