先整了一个类文件
//根据输入的SQL语句检索数据库数据
public DataSet SelectDataBase(string tempStrSQL, string tempTableName)
{
this.strSQL = tempStrSQL;
this.myConnection = new SqlConnection(connectionString);
this.da = new SqlDataAdapter(this.strSQL, this.myConnection);
this.ds.Clear();
this.da.Fill(ds, tempTableName);
return ds;//返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名
}
在需要的窗体中查询
LinkDataBase link = new LinkDataBase();
string sendTableName = "表名称";
sendStrSQL = "select InputDate, ArriveCompany, Event, InputMan, Term, Complete, CompleteDate, CompleteDesc, Re, InputOffice FROM 表名称 where " + strSQL;
this.ds = link.SelectDataBase(sendStrSQL, sendTableName);
this.DataGridView.DataSource = ds.Tables[0];
查询出符合条件的数据后,DataGridView控件里面有正确的行数出现,但是都是空白的,没有数据填充进去?
窗体Load的时候是使用
this.窗体名称TableAdapter.Fill(this.数据集名称.表名称)填充的
新手请教高手
//根据输入的SQL语句检索数据库数据
public DataSet SelectDataBase(string tempStrSQL, string tempTableName)
{
this.strSQL = tempStrSQL;
this.myConnection = new SqlConnection(connectionString);
this.da = new SqlDataAdapter(this.strSQL, this.myConnection);
this.ds.Clear();
this.da.Fill(ds, tempTableName);
return ds;//返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名
}
在需要的窗体中查询
LinkDataBase link = new LinkDataBase();
string sendTableName = "表名称";
sendStrSQL = "select InputDate, ArriveCompany, Event, InputMan, Term, Complete, CompleteDate, CompleteDesc, Re, InputOffice FROM 表名称 where " + strSQL;
this.ds = link.SelectDataBase(sendStrSQL, sendTableName);
this.DataGridView.DataSource = ds.Tables[0];
查询出符合条件的数据后,DataGridView控件里面有正确的行数出现,但是都是空白的,没有数据填充进去?
窗体Load的时候是使用
this.窗体名称TableAdapter.Fill(this.数据集名称.表名称)填充的
新手请教高手
数据层:
public class LinkDataBase
{
....
public DataSet SelectDataBase()
{
string sendStrSQL = "select InputDate, ArriveCompany, Event, InputMan, Term, Complete, CompleteDate, CompleteDesc, Re, InputOffice FROM 表名称 where " + strSQL;
string connectionString=".........";//这个你似乎没有定义连接数据库字符串
myConnection = new SqlConnection(connectionString);
da = new SqlDataAdapter(this.strSQL, this.myConnection);
ds.Clear();
da.Fill(ds);
return ds;//返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名
}
}
逻辑层:public class LuoJi
{
....
public DataSet GetDataDataSet()
{
return link.SelectDataBase(TempStrSQLs,TempTableNames);
}
}界面层......
public Luoji l=new Luoji();
private void .......
{
this.DataGridView.DataSource = l.GetDataDataSet().Tables[0].Defautview; //默认视图
}
逻辑层: C# code
public class LuoJi
{
....
public LinkDataBase link=new LinkDataBase();//补充个实例
public DataSet GetDataDataSet()
{
return link.SelectDataBase(TempStrSQLs,TempTableNames);
}
}
问题解决了,找到一个帖子,说是在窗体设计状态使用属性给DataGridView设定数据源,设定了列名等等,在手动读取的时候就不显示了。
myConnection.open();
this.da = new SqlDataAdapter(this.strSQL, this.myConnection);
this.ds.Clear();
this.da.Fill(ds, tempTableName);