| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2342 人关注过本帖
标题:[求助]显示数据问题
取消只看楼主 加入收藏
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
 问题点数:0 回复次数:27 
[求助]显示数据问题
我建了个TextBox,Button和DataGrid,希望在TextBox里输入一个查询字符串,按Button搜索,接着显示在DataGrid上。
在Button_Click事件上连接好了数据库,接着怎么显示到DataGrid上啊。
private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection thisConnection=new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;"+"Initial Catalog=student");
thisConnection.Open();
SqlCommand cmd=new SqlCommand("select Count(*) from 档案 where 学号='"+this.textBox1.Text+"' and 姓名='"+this.textBox2.Text+"'",thisConnection);


}

请高手指教
搜索更多相关主题的帖子: 数据库 Button DataGrid TextBox 
2006-08-04 15:40
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 

private void button1_Click(object sender, System.EventArgs e)
{

SqlConnection thisConnection=new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;"+"Initial Catalog=student");
thisConnection.Open();
SqlCommand cmd=new SqlCommand("select * from 档案 where 学号='"+this.textBox1.Text+"' and 姓名='"+this.textBox2.Text+"'",thisConnection);
SqlConnection con=new SqlConnection();
SqlCommand cmd2=new SqlCommand();
cmd2.Connection=con;
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd2;
DataTable dt=new DataTable();
da.Fill(dt);
this.dataGrid1.DataSource=dt;


}

我这样编译错误


2006-08-04 16:11
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 
名称“dt”在类或命名空间“学生管理系统.Main”中不存在
名称“dt”在类或命名空间“学生管理系统.Main”中不存在
找不到类型或命名空间名称“DataTable”(是否缺少 using 指令或程序集引用?)
划线处

2006-08-04 16:17
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 

编译成功了,
但是执行到查询的时候就中断
未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中。

其他信息: ConnectionString 属性尚未初始化。
怎么弄异常处理啊


2006-08-04 16:26
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 

在FILL数据库的时候出错了
咋办


2006-08-04 16:31
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 
看不懂,怎么放啊

2006-08-04 16:48
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 
private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection thisConnection=new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;"+"Initial Catalog=student");
thisConnection.Open();
SqlCommand cmd=new SqlCommand("select * from 档案 where 学号='"+this.textBox1.Text+"' and 姓名='"+this.textBox2.Text+"'",thisConnection);
SqlConnection con=new SqlConnection();
SqlCommand cmd2=new SqlCommand();
cmd2.Connection=con;
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
DataTable dt=new DataTable();
da.Fill(dt);
this.dataGrid1.DataSource=dt;
}

我这样编译成功,但是还是按查询后还是没有在DataGrid里面出现数据

2006-08-04 17:18
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 
private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection thisConnection=new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;"+"Initial Catalog=student");
thisConnection.Open();
SqlCommand cmd2=new SqlCommand("select * from 档案 where 学号='"+this.textBox1.Text+"' and 姓名='"+this.textBox2.Text+"'",thisConnection);
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
DataTable dt=new DataTable();
da.Fill(dt);
this.dataGrid1.DataSource=dt;
}

提示 名称“cmd”在类或命名空间“学生管理系统.Main”中不存在


象你这样写,红色地方还是出问题,是不是我哪里设置有问题啊

2006-08-04 17:36
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 



郁闷
郁闷
郁闷
郁闷
郁闷
郁闷
郁闷
郁闷
郁闷
郁闷
郁闷
郁闷
郁闷


2006-08-04 17:45
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 

改过了啊,改完后连编译都成功不了


2006-08-04 17:58
快速回复:[求助]显示数据问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013186 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved