I have a WPF application. date
is my table and its two columns are employeename
(varchar(10)
) and date
(datetime
)
My code is:
Sqlconncetion con = new Sqlconnection("my database connection ");
SqlCommand cmd = new SqlCommand("insert into date values('"+textBox1.Text+"','"+datePicker1.Text+"')", con);
con.Open();
int n = cmd.ExecuteNonQuery();
if (n > 0)
{
MessageBox.Show("insert");
}
Actually my WPF datepicker
formats inputs as "dd/mm/yyyy
" and SQL Server table accept date format mm/dd/yyyy
. How can I change my SQL Server datetime
datatype date format? please give solution by code in c#..
My task is to display all name and birth date. My condition is basic but at time of date selection and button enter, I get exception. My code is
SqlConnection con = new SqlConnection("my connection ");
SqlDataAdapter da = new SqlDataAdapter("select name,date from date where date between'"+ Convert.ToDateTime( datePicker2.SelectedDate)+"' and '"+ Convert.ToDateTime( datePicker3.SelectedDate)+"'",con);
DataSet ds = new DataSet();
da.Fill(ds, "entry");
da.Dispose();
dataGrid1.DataContext = ds.Tables["entry"].DefaultView;
plz help me solve code error and write correct code . this is a WPF application.