sql server - SQL Command not working in C# Windows Form Application -


I add a new column to a table in a table through my Windows Forms application (created using C #) I am trying to / P>

I have created a method CreateFieldNameInTableData (String Field Name, String TableName), which passes through the name of the 'field name' variable, which is the column to be added to the table, the 'tablename' Can be specified by.

The code of this method, which is trying to add columns to the table, is as follows:

  Private Zero CreateFieldNameInTableData (String Field Name, String Assertip Cod) {SqlConnection conn = New SqlConnection (SQLConnectionString); SqlCommand Com = Null; Try {try} {comm = conn.CreateCommand ()} Comm.CommandText = "Optional Table [ASDL + + Table Name +" _DATA] Add "+ FieldName +" VARCHAR (30) "; Comm.CommandType = CommandType.Text; Comm.CommandTimeout = 30; // 30 seconds conn.Open ();} Hold (SqlException err) {message box. Show ("SqlException error:" + err.Message.ToString ());}} Hold (Exception pre) {Message box.show ("Exception error:" + pre-message .tostring ());} Finally {conn.Close ();}}  

When I'm in Server Management Studio I am using the same SQL script, I It is successfully creating columns in AS_TableName_DATA, but when I'm trying to do this using C #, there is no error throwing, but after inspection, there is no new column in the table that needs to be created.

Any help ... What's going wrong?

PS I also checked the SQLConnectionString, which is also connected to the correct database.

As suggested by @TarasB, Comm.ExecuteNonQuery () Dh was SQL query C # SQLClient was performed by feels like looking back to this error a 'school boy error'.

The last working code is as follows:

  try {comm = conn.CreateCommand ()} Comm.CommandText = "Optional table [ASDL + + Table name +" _DATA] ADD ["+ FieldName +"] VARCHAR (30) "; Comm.CommandType = CommandType.Text; Comm.CommandTimeout = 120; // 120 seconds conn.Open (); comm.ExecuteNonQuery ();} Hold (SqlException Err) {message box. Show ("SqlException error:" + err.Message.ToString ());}  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -