This is my first time creating a DAL for a website, and I am running into a sort of hairy error. I am attempting to perform an update of a smalldatetime field in my table, but when I do so, I get an error that reads:
Conversion failed when converting character string to smalldatetime data type
Here is the snippet of code that I am using to update the DataRow:
Am I missing something terribly wrong here? I am parsing the text from the textbox as datetime, and when I view the SQL statement as it is passed to the SQL server (through SQL Server Profiler) the date looks correct. Any help would be greatly appreciated! Thanks!
Conversion failed when converting character string to smalldatetime data type
Here is the snippet of code that I am using to update the DataRow:
Code:
protected void btnSubmit_Click(object sender, EventArgs e)
{
timeoffTableAdapter db = new timeoffTableAdapter();
timeoff.timeoffDataTable dt = db.GetDataByReqid(Convert.ToInt32(Request.QueryString["reqid"]));
DateTime dtfrom = DateTime.Parse(txtdtfrom.Text.Trim());
DateTime dtto = DateTime.Parse(txtdtto.Text.Trim());
foreach (timeoff.timeoffRow drow in dt)
{
[COLOR=red]drow.dttakenfrom = dtfrom;[/color]
[COLOR=red]drow.dttakento = dtto;[/color]
drow.takencomm = txtcomm.Text.Trim();
drow.typeid = Convert.ToInt32(rblTOType.SelectedValue);
}
db.Update(dt);
Response.Redirect("tosent.aspx");
}
Am I missing something terribly wrong here? I am parsing the text from the textbox as datetime, and when I view the SQL statement as it is passed to the SQL server (through SQL Server Profiler) the date looks correct. Any help would be greatly appreciated! Thanks!