Sunday, 15 January 2012

C# SQL Syntax Error -


Can anyone tell me why when I add an area in this SQL Server database I get the error Attempts

Wrong syntax near the keyword 'Table'

Code:.

  {// TODO: This line of code loads the data in the 'TBoxDataSet.Table' table. You can move, or remove it, as needed. This.tableTableAdapter.Fill (this.tboxDataSet.Table); } Private void button1_Click (Object Sender, EventArgs e) {SqlConnection cn = New SqlConnection (Global :: TicketBox.Properties.Settings.Default.TBoxConnectionString); Try using {{SqlConnection Connect = New SqlConnection (Global :: TicketBox.Properties.Settings.Default.TBoxConnectionString) in the table (@ "use (SqlCommand runsql = new SqlCommand (EVENT_ID, artist, location, date, time) , Ticket) Values ​​(@ EventID, @ Artist, @Venue, @date, @ time, @tk), Connect) {runsql.Parameters.Add ("@ EventID", SqlDbType.Int) .Value = textBox1.Text ; Runsql.Parameters.Add ("Artist", SqlDbType.VarChar) .Value = textBox2.Text; Runsql.Parameters.Add ("@post", SqlDbType.VarChar) .Value = textBox3.Text; Runsql.Parameters.Add ("Date", SqlDbType.Date) .Value = textBox4.Text; Runsql.Parameters.Add ("@time", SqlDbType.Time) .Value = textBox5.Text; Runsql.Parameters.Add ("Ticket", SqlDbType.Int) .Value = textBox6.Text; Connect.Open (); Runsql.ExecuteNonQuery (); } MessageBox.Show ("Event added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); This.tableTableAdapter.Fill (this.tboxDataSet.Table); } Hold (Exception pre) {Message Box. Show (ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Finally {cn.Close (); }  

table and time In T-SQL, you need to use them with square brackets such as [table] and [time] .

As a best practice, replace them with non-reserved - words.

In addition, the date can be a reserved keyword in future releases of SQL Server. You also have to use it with square brackets.


No comments:

Post a Comment