im doing a project and i want to add a record to an accdb using a windows forms application on c# i have got what appears to be code that works i.e. it doesnt show any errors and appears to run however it doesnt add the record il post the code any ideas or help would be much appreciated

private void confirmbut_Click(object sender, EventArgs e)
        {
            OleDbConnection Conn = new OleDbConnection (
                "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= H:\\VRUSLTD\\VRUS.accdb");
            
            OleDbCommand Cmd = new OleDbCommand
                ("INSERT INTO Rental_Details(RentalID,Reg_No,CustID,StaffMember,PickUpDate,PickUpTime,Due_Back,DaysRental) SELECT '" +
                                       rentIDtb.Text + "','" + vehIDtb.Text + "','" + custIDtb + "','" + empIDtb + "','" + pickuptb + "','" + picktimetb + "','" + returntb + "','" + daystb + "';", Conn);
        }

items names with tb at the end of there names are textboxes eg returntb , days tb

What you want is INSERT INTO ... VALUES(...): http://msdn.microsoft.com/en-us/library/bb208861.aspx, because the INSERT INTO ... SELECT FROM inserts fields FROM another table and you want to insert your TextBox.Text VALUES into your table.

It is unclear to me why you have what appears to be mixture of controls and control Text (eg. "rentaltb.Text", but "daystb") when they both appear to be named as though they are both TextBox controls ("tb" designation), but you don't reference the Text property in both places. Perhaps the latter is actually a string and not really a TextBox ...

Edited 7 Years Ago by DdoubleD: n/a

AS DdoubleD pointed out, you are correctly using the .Text property on some values but passing the control in others.
Also, while there are no hard and fast rule for naming conventions, it is common to use a prefix rather than suffix to identify control types. For example, tbPickup (although txt is generally used for textboxes: txtPickup).
Also, pascal/camel casing can make names easier to read; there is a breakdown of when to use the casings over at msdn.

This article has been dead for over six months. Start a new discussion instead.