按标题文字大小写对值排序 [英] sort values by header text match case
问题描述
朋友!
我自己的视觉
请解决我的问题并纠正正确的代码.拜托,这是我的要求.问题是我必须使用像这样的sql查询对datagridveiw中的csv文件进行排序
Hi friend!
Myself vishal
Please solve my problem and right a correct code. Please it''s my request. Problem is that I have to sort a csv file in datagridveiw by use a sql query like this
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,LAST_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);
dataset.Clear();
adapter.Fill(dataset, "Test");
olconn.Close();
}
return dataset;
}
public void Process_Click(object sender, EventArgs e)
{
try
{
DataSet dataset = Form1.Getdataset1(textbox1.Text);
Datagidveiw1.DataSource = dataset.Tables[0].DefaultView;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}//code is:
string cmdstring = string.Format(@select * FROM {0} order by IN_NO desc,FIRST_DATE asc,LAST_DATE asc, Path.GetFileName(filename1));
它工作得很好,但问题是如果IN_NO作为标题文本(如"IN no"或"Pn no")sql查询不匹配且操作失败.
我知道我可以获取索引位置的位置,但标题文本可以更改其位置,我想说的是,如果In_no在第一个csv文件中位于[0]索引位置,但是在其他文件中则位于[2]索引中因此使用sql查询会更好,但我想我也可以使用大小写条件,并在此条件下运行多个sql查询以进行数学运算,但如何使用在此代码中,我不知道.
plesae解决了我的问题.
我会感谢你的.
:rose:
It works very good but a problem is If IN_NO as a header text like this "IN no" Or "Pn no" sql query not match and operation failed.
I know I can take index number for purticular location but Header text can be change their location as another words I want to say that if In_no In fist csv file at [0] index location but in other file it is on a [2] index so Its a better to take sql query but I think I can also use a case condition and run multiple sql query on this for math but how use In this code , I do not know .
plesae solve my problem.
I will be thankful to you.
:rose:
推荐答案
为什么不尝试首先读取列名称,然后如果发现"IN no"或"IN_NO",您将能够获取正确的列索引并根据获取的索引创建动态SQL.
这样,您也可以处理是否根本找不到"IN no"或"IN_NO"列名称.
Why don''t you try reading the column names first, then if you find "IN no" or "IN_NO" you''ll be able to get the correct column index and create a dynamic SQL based on the index you get.
In this way you can also handle if "IN no" or "IN_NO" column name is not found at all.
这篇关于按标题文字大小写对值排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!