一个关于DataGrid和DataView的问题,很棘手!!
private void Button1_Click(object sender, System.EventArgs e)
{
string sqlstring="Provider=MSDAORA.1;User ID=scott;Data Source=orac9i;Password=tiger";
string sqlstring2="select * from student3 where loginid="+"'"+TextBox1.Text+"'";
OleDbConnection con=new OleDbConnection(sqlstring);
try
{
con.Open();
Button1.Text="连接成功";
OleDbDataAdapter sqlAda = new OleDbDataAdapter(sqlstring2,con);
sqlAda.SelectCommand.CommandType=CommandType.Text;
DataSet ds = new DataSet();
sqlAda.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}
catch (Exception ex)
{
Button1.Text="asdfasdf";
}
finally
{
con.Close();
}
不难看出,点击Button1这个按钮,则以TextBox1中的内容为参数查询数据库,生成数据集.但因为student3这个表中的字段很多,我不想一下
子都在DataGrid1中显示,我只想显示几个字段,请问怎么通过代码实现.另外,查看一行的所有内容,我想通过点击DataGrid1中的某一行,然后
在页面中DataGrid1的下面放几个Label控件来显示这行各个字段的内容,我知道可能要用到dataview.请高手帮忙 ,能不能帮我写成这些代码,最好写的详细些.谢谢谢谢谢谢!!!!!!!!!