Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried execute INSERT query, but it throwing above error. I have given my code below

C#
public string InsertMoveDetails(string desc, string currentLocation, string newLocation, string newBay, string requestedBy, string movedBy, string approvedBy, DateTime dateOfMove)
    {

string desc, currentLocation, newLocation, movedBy, approvedBy, requestedBy,newBay;
        DateTime dateOfMove;

        desc = textBoxDescription.Text;
        currentLocation = textBoxCurrentLocation.Text;
        newLocation = comboBoxNewLocation.Text;
        movedBy = comboBoxMovedBy.Text;
        approvedBy = comboBoxApprovedBy.Text;
        dateOfMove = dateTimePickerDateOfMove.Value;           
        newBay = textBoxNewBay.Text;
        requestedBy = textBoxRequestedBy.Text;

        con.Open();
        OleDbCommand cmd1 = new OleDbCommand("INSERT INTO MoveDetails(Descrptn, CurrentLocation, NewLocation, NewBay, RequestedBy, MovedBy, ApprovedBy, DateOfMove) VALUES(@Descrptn, @CurrentLocation, @NewLocation, @NewBay, @RequestedBy, @MovedBy, @ApprovedBy, @DateOfMove)", con);

        cmd1.Parameters.AddWithValue("@Descrptn", desc);
        cmd1.Parameters.AddWithValue("@CurrentLocation", currentLocation);
        cmd1.Parameters.AddWithValue("@NewLocation", newLocation);
        cmd1.Parameters.AddWithValue("@NewBay", newBay);
        cmd1.Parameters.AddWithValue("@RequestedBy", requestedBy);
        cmd1.Parameters.AddWithValue("@MovedBy", movedBy);
        cmd1.Parameters.AddWithValue("@ApprovedBy", approvedBy);
        cmd1.Parameters.AddWithValue("@DateOfMove", dateOfMove);

        cmd1.ExecuteNonQuery();
        con.Close();
        return "";
    }


My database design is
Descrptn- Text
CurrentLocation- Text
NewLocation- Text
NewBay- Text
RequestedBy- Text
MovedBy- Text
ApprovedBy- Text
DateOfMove- Date/Time

Please help me with this error. I tried the other threads with same error, but i can't find the answer.
Posted

There is nothing obvious to me in that: the data types look right - which leaves only the data.

So start with the debugger.
Put a breakpoint on the line:
C#
cmd1.ExecuteNonQuery();
And run your app.
When it hits the breakpoint, it will stop. You can then look at the data you are loading into each parameter and see exactly what they are. At a guess, either the date is outside SQL limits, or one of the other fields is returning a value which isn't allowed in your DB - a null, or too large a string perhaps.

But without the actual data? Nothing we can do to help, I'm afraid.
 
Share this answer
 
Comments
Sarath kumar.N 4-Jun-15 3:48am    
Yeah I tried that step. The sample values are
desc="Samsung Laptop"
CurrentLoaction="Bodhi"
NewLocation="ODC1"
MovedBy="Sarath,Kumar"
RequestedBy="Kamal"
ApprovedBy="Guna,Sekar"
DateOfMove={04-06-2015 PM 1:13:01}
I tried with this code.

C#
dateOfMove = Convert.ToDateTime(dateTimePickerDateOfMove.Text);

That's works for me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900