Click here to Skip to main content
15,895,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i am passing datetime.now.tostring() as parMETER IN MY SQL QUERY for retriving all the transaction of todays.but unable to retrive.
please help me.

my query like:
select billno,net amount from bill_details where date='" +DateTime.Now.Tostring() + "';
Posted

1 solution

First: You are not using a parameter, it's just passed into a string.

Second: "net amount" there can be NO spaces in column names within your table.

Third: Tostring() does not exist. It has to be ToString();

How this should be done is:

(My demo uses OleDb but the practice is overall the same)

C#
string sqlQuery = "SELECT billno, net_amount FROM bill_details WHERE date=@Date";

OleDbCommand sqlCommand = new OleDbCommand(sqlQuery, sqlConnection);
sqlCommand.Parameters.Add("@Date", OleDbType.VarChar).Value = DateTime.Now.ToString();

OleDbDataAdapter sqlAdapter = new OleDbDataAdapter(sqlCommand);

DataSet ds = new DataSet();
sqlAdapter.Fill(ds);


Now all information should be in DataSet ds. And can be bound as a DataSource to a DataGridView or be read manually progammetically.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900