c# - how to create a table having spaces between the words? -
i trying create table using code.
here code.
private void btnok_click(object sender, eventargs e) { if (con.state == connectionstate.open) { con.close(); } con.open(); string s = "create table "+"" + rchtxtfieldcode.text + " "+ " (" + rchfieldtitle.text + " " + combdatatype.text + "" + ")"; sqlcommand cmd = new sqlcommand(s, con); if (cmd.executenonquery() >= 1) { messagebox.show("created"); } con.close(); } it creating table if table name has single word.. showing exception if there space between words(eg: sales info)
just add box braces:
string s = "create table ["+"" + rchtxtfieldcode.text + "] "+ " (" + rchfieldtitle.text + " " + combdatatype.text + "" + ")"; //^_______________________________^
Comments
Post a Comment