database - C# Listview , Data type Mismatch on insertion of record -
i want insert data database using c# below error
error:data type mismatch when try execute cmd1.executenonquery();
private void btnfirst_click(object sender, eventargs e) { constring =properties.settings.default.transportationconnectionstring; con.connectionstring = constring; system.data.oledb.oledbcommand cmd1 = new system.data.oledb.oledbcommand(); cmd1.connection = con; cmd1.commandtext = "insert [billinggrd] ([invoiceno],[fromlocation],[tolocation],[material],[trip],[metricton],[billweight],[rate],[billamount],[grandtotal]) values (@invoiceno,@fromlocation,@tolocation,@material,@trip,@metricton,@billweight,@rate,@billamount,@grandtotal)"; for(inc=0;inc<listview1.items.count;inc++) { cmd1.parameters.addwithvalue("@invoiceno", txtbilno.text); cmd1.parameters.addwithvalue("@fromlocation", listview1.items[inc].subitems[0].text); cmd1.parameters.addwithvalue("@tolocation", listview1.items[inc].subitems[1].text); cmd1.parameters.addwithvalue("@material", listview1.items[inc].subitems[2].text); cmd1.parameters.addwithvalue("@trip", listview1.items[inc].subitems[3].text); cmd1.parameters.addwithvalue("@metricton", listview1.items[inc].subitems[4].text); cmd1.parameters.addwithvalue("@billweight", listview1.items[inc].subitems[5].text); cmd1.parameters.addwithvalue("@rate", listview1.items[inc].subitems[6].text); cmd1.parameters.addwithvalue("@billamount", listview1.items[inc].subitems[7].text); cmd1.parameters.addwithvalue("@grandtotal", textbox1.text); } con.open(); cmd1.executenonquery();//error here datatype mismatch con.close(); }
try might work you..... if not let me know comment
private void btnfirst_click(object sender, eventargs e) { constring =properties.settings.default.transportationconnectionstring; con.connectionstring = constring; system.data.oledb.oledbcommand cmd1 = new system.data.oledb.oledbcommand(); cmd1.connection = con; for(inc=0;inc<listview1.items.count;inc++) { cmd1.commandtext=""; con.open(); cmd1.commandtext = "insert [billinggrd] ([invoiceno],[fromlocation],[tolocation],[material],[trip],[metricton],[billweight],[rate],[billamount],[grandtotal]) values ('"+txtbilno.text+"','"+listview1.items[inc].subitems[0].text+"','"+listview1.items[inc].subitems[1].text+"','"+listview1.items[inc].subitems[2].text+"','"+listview1.items[inc].subitems[3].text+"','"+listview1.items[inc].subitems[4].text+"','"+listview1.items[inc].subitems[5].text+"','"+listview1.items[inc].subitems[6].text+"','"+listview1.items[inc].subitems[7].text+'")"; cmd1.executenonquery();//error here datatype mismatch con.close(); } }
Comments
Post a Comment