按区分大小写在数据集中运行SQL语句 [英] RUN SQL STATEMENT IN DATASET by match case
本文介绍了按区分大小写在数据集中运行SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
开发人员,
我正打算在数据集中运行多个sql语句.
我的代码是:
Hi Developer,
I am tring to run multiple sql statements in dataset.
My code is:
public static DataSet Getdataset1(string filename1)
{
string Connectionstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Text;",
Path.GetDirectoryName(filename1));
string cmdstring = string.Format(@"select * FROM {0} order by IN_no desc,FIRST_DATE asc,END_DATE asc", Path.GetFileName(filename1));
string cmdstring1 = string.Format(@"select * FROM {0} order by IN no desc,FIRST DATE asc,END DATE asc",
Path.GetFileName(filename1));
string cmdstring2 = string.Format(@"select * FROM {0} order by Pd_no desc,FIRST_DATE asc,END DATE asc", Path.GetFileName(filename1));
DataSet dataset = new DataSet();
using (OleDbConnection olconn = new OleDbConnection(Connectionstring))
{
olconn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(cmdstring, olconn);
adapter.SelectCommand= new OleDbCommand(cmdstring1, olconn);
adapter.SelectCommand= new OleDbCommand(cmdstring2, olconn);
dataset.Clear();
adapter.Fill(dataset, "Test");
olconn.Close();
}
return dataset;
}
public void Process_Click(object sender, EventArgs e)
{
try
{
DataSet dataset = Form1.Getdataset1(Locations.Text);
Datagidveiw1.DataSource = dataset.Tables[0].DefaultView;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
当我想对数据进行排序时会发生错误.
{"IErrorInfo.GetDescription失败,出现E_FAIL(0x80004005)."}
实际上我想在cmdstring
之间创建一个匹配条件,然后匹配列的标题文本,然后仅运行一个sql语句对数据进行排序.
我该如何提出建议?
请接受此请求.
The error occurs when I want to sort data.
{"IErrorInfo.GetDescription failed with E_FAIL(0x80004005)."}
Actually I want to create a match condition between cmdstring
and after match the headertext of columns and then only one sql statement is run to sort data.
How can I create that, any suggestions?
Please accept this request
推荐答案
cmdstring1 SQL语句中有一个小小的错误.看看是否可以找到缺少的字符.您所要做的就是将它与上面的行进行比较.
哦,DataAdpapter一次只能保存一个选择查询.您的查询仅返回最后一个,而不返回其他两个.您必须分别执行3次填充来填充数据集,并且必须确保返回的每个表都具有不同的名称,这样您才不会用新的查询覆盖以前的数据.
There is a tiny little bug in the cmdstring1 SQL statement. See if you can find themissing character. All you have to do is compare it to the line above it.
Oh, and a DataAdpapter can only hold ONE select query at a time. Your query is returning the last one only, not the other two. You have to execute a fill 3 seperate times to fill the dataset AND you have to make sure that each table returned has a different name so you''re not overwriting the previous data with the new query.
这篇关于按区分大小写在数据集中运行SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文