c# - Insert float values to Access -


this code, inserts values in ms access. doesn't insert float values, 0.45. column datatype text

private void button1_click(object sender, eventargs e) {     oledbcommand cmd = con.createcommand();     con.open();     cmd.commandtext = "insert hhh values('" + textbox1.text + "','" +textbox2.text + "','" + textbox3.text + "','" + textbox4.text + "')";     cmd.connection = con;     cmd.executenonquery();     messagebox.show("record submitted", "congrats");     con.close(); } 

you insert text while float number. also, ensure proper string expression of value, textbox1:

string text1; // text1 must formatted dot decimal separator. system.globalization.cultureinfo culture = system.globalization.cultureinfo.invariantculture; text1 = convert.todouble(textbox1.text).tostring(culture);  cmd.commandtext = "insert hhh values (" + text1 + ",'" +textbox2.text + "','" + textbox3.text + "','" + textbox4.text + "')"; 

that said, do use parameters - simpler, proven, , preferred.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -