Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error updating DataRow in DAL object

Status
Not open for further replies.

sunmorgus

Programmer
Nov 9, 2004
81
0
0
US
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:

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!
 
Is there a better way that I should be doing it?
 
This is a fairly well put together DAL.


Then you implement all of your own SQL. This makes your queries faster and more effecient.

Once you have your results in a DataSet you can either use them in the DataSet directly or break them out into objects/beans.

You can use tableadapters but you have to be really careful how you use them. A table adapter gives you the power to affect the database from the GUI directly, which defeats the purpose of a layered application.

 
Actually, I figured it out. It wasn't the update in the code that was the problem, but a trigger that I added to the table recently. Thanks for the help though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top