标题:[求助] 查询和datagrid 的问题
只看楼主
skyland84
Rank: 2
等 级:新手上路
威 望:4
帖 子:544
专家分:0
注 册:2006-10-9
得分:0 

private void Form2_Load(object sender, EventArgs e)
{
cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename="+@"D:\Documents and Settings\soft-2003\My Documents\myex.mdf"+";Integrated Security=True;Connect Timeout=30;User Instance=True");
string com = "select * from nihaoma";
ad = new SqlDataAdapter(com, cn);
cn.Open();
ad.Fill(data);
dataGrid1.DataSource = data;
cn.Close();
}

private void huanToolStripMenuItem_Click(object sender, EventArgs e)
{

string com = "select ni from nihaoma";
ad = new SqlDataAdapter(com, cn);
cn.Open();
data.Clear();//////清除所有的表
ad.Fill(data);
//dataGrid1.tables
dataGrid1.DataSource = data;//再重新定向 数据源
cn.Close();
}


决定人生~
2006-11-13 14:02
skyland84
Rank: 2
等 级:新手上路
威 望:4
帖 子:544
专家分:0
注 册:2006-10-9
得分:0 

你设置 的 是局部变量 还是 全局啊?


决定人生~
2006-11-13 14:08
wangxi267
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-10-22
得分:0 

private void show()
{
string connstr,selectcmd;
connstr =
"Server=LENOVO-8AD35F65;database=ZXMR;uid = sa;pwd = sa;";
selectcmd = "SELECT * FROM MIS_Doctor ORDER BY DoctorID DESC";
SqlConnection conn;
SqlDataAdapter myadapter;
DataSet mydataset = new DataSet();
conn = new SqlConnection(connstr);
myadapter = new SqlDataAdapter(selectcmd,conn);
myadapter.Fill(mydataset,"MIS_Doctor");
dataGrid1.DataSource = mydataset.Tables["MIS_Doctor"];

}

private void DBasicMessage_Load(object sender, System.EventArgs e)
{
show();
}

private void btnbs_Click(object sender, System.EventArgs e)
{
string dname,dzhicheng,dlevel;
dname = this.textBox1.Text;
dzhicheng = this.textBox2.Text;
dlevel = this.textBox3.Text;

string connstr,selectcmd;
connstr = "Server=LENOVO-8AD35F65;database=ZXMR;uid = sa;pwd = sa;";

SqlConnection conn = new SqlConnection(connstr);
conn.Open();

selectcmd = "SELECT * FROM MIS_Doctor where DoctorName = '" + dname + "'";

SqlDataAdapter myadapter = new SqlDataAdapter(selectcmd,conn);

DataSet mydataset = new DataSet();

myadapter.Fill(mydataset);

dataGrid1.DataSource = mydataset;
conn.Close();

结果出来了 还是有点小问题

2006-11-13 14:12
wangxi267
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-10-22
得分:0 

朋友加我QQ 125284853谈论

[此贴子已经被作者于2006-11-13 14:13:04编辑过]

2006-11-13 14:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-102594-1-1.html




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

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