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);
}
}
}
string cmdstring = string.Format(@select * FROM {0} order by IN_NO desc,FIRST_DATE asc,LAST_DATE asc, Path.GetFileName(filename1));
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: