Good morning
I have this 2 lines to get the date time
txtdate.Text= DateTime.Now.Date.ToString();
string dt = Convert.ToDateTime(txtdate.Text).ToString();
and i pass it to the stored procedure as parameter as following :
cmd.Parameters.AddWithValue("@Reg_Date", dt);
when it reach the cmd.ExecuteNonQuery();
it will stop and give the error :
Error converting data type nvarchar to datetime
thanks in advance
Loading

venkata kumarRank #5,034 · 314 reputationPosted Feb 26, 2013, 11:26 PM EST
try this
txtdate.Text= DateTime.Now.Date.ToString();
string dt = (txtdate.Text);
otherwise what is format of datetime is "dd//MM/yyyy" or mm/dd/yyyy"
ToBe152 reputationPosted Feb 27, 2013, 12:12 AM EST
I tried it but I'm still getting the same error :(
venkata kumarRank #5,034 · 314 reputationPosted Feb 27, 2013, 1:31 AM EST
while sending back you need to convert "dd/MM/yyyy" to MM/dd/yyyy"
try this the fallowing
txtdate.Text= DateTime.Now.Date.ToString();
string dt = (txtdate.Text);
string[] s = dt.ToString().Split('/');
string strDob = s[1] + "/" + s[0] + "/" + s[2];
dt=strdob;
cmd.Parameters.AddWithValue("@Reg_Date", dt);
ToBe152 reputationPosted Feb 27, 2013, 1:43 AM EST
I tried your code and the error is not coming but it's adding Null value in the database for Reg_Date .
ToBe152 reputationPosted Feb 27, 2013, 4:42 AM EST
any reply plz for the this issue :(