| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2342 人关注过本帖
标题:[求助]显示数据问题
只看楼主 加入收藏
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
[CODE]
using (SqlConnection connection =
new SqlConnection((@"Data Source=(local);Integrated Security=SSPI;"+"Initial Catalog=student"))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("select * from 档案 where 学号='"+this.textBox1.Text+"' and 姓名='"+this.textBox2.Text+"'", connection);
DataTable dt=new DataTable();
da.Fill(dt);
this.dataGrid1.DataSource=dt;
this.dataGrid1.DataBind();
}

[/CODE]

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-04 16:31
xxxxx52
Rank: 4
等 级:贵宾
威 望:13
帖 子:689
专家分:0
注 册:2006-4-30
收藏
得分:0 
Fill的不是数据库吧? 就只是一个datatable

好的资料下载网站http:///in.asp?id=xuelion2006 嘿嘿帮点一下拉~
2006-08-04 16:45
xxxxx52
Rank: 4
等 级:贵宾
威 望:13
帖 子:689
专家分:0
注 册:2006-4-30
收藏
得分:0 
string con="uid=sa;pwd=;database=power;server=127.0.0.1";
连接字符串这个样写就足够拉... 最起码winform是够了

好的资料下载网站http:///in.asp?id=xuelion2006 嘿嘿帮点一下拉~
2006-08-04 16:47
coolfaith
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-4-25
收藏
得分:0 
看不懂,怎么放啊

2006-08-04 16:48
xxxxx52
Rank: 4
等 级:贵宾
威 望:13
帖 子:689
专家分:0
注 册:2006-4-30
收藏
得分:0 
SqlConnection con=new SqlConnection("uid=sa;pwd=;database=power;server=127.0.0.1");

好的资料下载网站http:///in.asp?id=xuelion2006 嘿嘿帮点一下拉~
2006-08-04 16:56
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
SqlConnection thisConnection=new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;"+"Initial Catalog=student");


他用的集成驗證

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-04 17:01
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
以下是引用coolfaith在2006-8-4 16:11:37的发言:

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;


}

我这样编译错误

你初始化的是cmd 調用的cmd2 當然錯


[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-04 17:03
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
xxxxx52
Rank: 4
等 级:贵宾
威 望:13
帖 子:689
专家分:0
注 册:2006-4-30
收藏
得分:0 
SqlCommand cmd=new SqlCommand("select * from 档案 where 学号='"+this.textBox1.Text+"' and 姓名='"+this.textBox2.Text+"'",thisConnection);

SqlCommand cmd2=new SqlCommand();
你用的第2个 是空的 怎么会出现数据呢?


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;
}

这个样就没问题了

好的资料下载网站http:///in.asp?id=xuelion2006 嘿嘿帮点一下拉~
2006-08-04 17:31
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
快速回复:[求助]显示数据问题
数据加载中...
 
   



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

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