I'm fetching date from the database and following is my command for it:
SqlCommand cmd = new SqlCommand("select dob from sample Where cardnum = '" + TextBox1.Text + "'");
How do i save the output of this command into datetime?
I'm fetching date from the database and following is my command for it:
SqlCommand cmd = new SqlCommand("select dob from sample Where cardnum = '" + TextBox1.Text + "'");
How do i save the output of this command into datetime?
At the simplest:
var when = (DateTime)cmd.ExecuteScalar();
However, in the more general case you woulnd need to know about readers and parameters. Or: use a tool like dapper:
var when = conn.Query<DateTime>(
"select dob from sample Where cardnum = @num",
new { num = TextBox1.Text } // parameters, done right
).Single();
But dapper will read entire objects too (mapping properties to columns), not just single values.