Click here to Skip to main content
15,909,530 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frnds...
Am Creating an application which the database table is created dynamically the thing is now i need to change my data type varchar(max) to int also to set an primary key and Auto incremnt the value pls do guide me...I got an error as

In Correct Syntax near Int32


Here is my code

C#
foreach (DataColumn dc in dt.Columns)
               {
                   if (exists == null)
                   {
                       SqlCommand createtable = new SqlCommand("CREATE TABLE " + TextBox1.Text + " (" + TextBox1.Text.Substring(0, 1) + "ID" + " sizeof(Int32) )", con);
                       createtable.ExecuteNonQuery();
                       exists = dt.TableName;
                   }

               }


               SqlCommand addcolumn = new SqlCommand("ALTER TABLE " + TextBox1.Text + " ADD " + TextBox2.Text + " varchar(MAX)," + TextBox3.Text + " varchar(MAX) ," + TextBox4.Text + " varchar(MAX)," + TextBox5.Text + " varchar(MAX)," + TextBox6.Text + " varchar(MAX)," + TextBox7.Text + " varchar(MAX)," + TextBox8.Text + " varchar(MAX)", con);
               addcolumn.ExecuteNonQuery();
               Session["tablename"] = TextBox1.Text.ToString();

               break;



Thank You..,
Posted

1 solution

problem is sizeof(int32) remove it and keep bigint
 
Share this answer
 
Comments
usha C 25-Jul-13 3:34am    
Ya sir its right...can u pls tel me hw to declare the primary key and auto incremn wit dis code...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900