I want to add new field when user enter text in text box and click on create then in the database table new field is create with the name present in text box

I use this code to do this but it takes a8 as new field

can i use this line of code to do this but it give me error message that one or more argument cant use.

string q = ("alter table abc add'"+textbox1.text.tostring()+" varchar(20)"+"'",cn);

this is my code:

SqlConnection cn = new SqlConnection();
            cn.ConnectionString = "Data Source=WELL\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True";
            cn.Open();
            string s;
            s = textBox1.Text;
            string q = "alter table abc add a8 varchar(20)";
            SqlCommand cmd = new SqlCommand(q, cn);
            cmd.ExecuteReader(); 
            //cmd.Parameters.Add(new SqlParameter(cmd, cn));
            SqlDataReader dr = cmd.ExecuteReader();
            cn.Close();
SqlConnection cn = new SqlConnecton();
cn.ConnectionString = "Data Source=WELL\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True";
string s;
s = textbox1.Text;   ?
string q = "ALTER TABLE abc add '"+textbox1.Text+"' Varchar(20)";
//string q = "ALTER TABLE abc add a8 Varchar(20)";
SqlCommand cmd = new SqlCommand(q, cn);
cn.Open();
cmd.ExcecuteNonQuery();
cn.Close();

Not sure why you were using the reader

Edited 5 Years Ago by Fenrir(): n/a

waht ever text i enter in text box it show me an error message that incorrect syntax near "a9"/ text in textbox

Edited 5 Years Ago by virusisfound: n/a

I use this line of code for create new table but it give me error message that incorrect syntex near "("

string q = "create table"+textbox1.text.tostring+"varchar(20),crd varchar(20),deb varchar(20)";

Why this error occured..
I dont know what is wrong in it..

Either i dont know the proper syntex Please can any one correct my mistakes...

Edited 5 Years Ago by virusisfound: n/a

string q = "create table MyTable ("+textbox1.Text +" varchar(20),crd varchar(20),deb varchar(20))";
This question has already been answered. Start a new discussion instead.