I want to create a program that save/deletes/edits database files. For example I want to enter this info to the database:
Name: John
Surname: Johnson
Father's name: Johnson
Offers used: 10
Age: 20
And all this to be saved or edited or removed. But when I try to make this
- I can't change the database table name
I get this error:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near the keyword 'Table'.
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Photography_Register
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Ivan\Documents\db.mdf;Integrated Security=True;Connect Timeout=30");
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Table values('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"')";
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Data about " + textBox1.Text + " " + textBox3.Text + " has been successfully" + "\r" + "uploaded to server!");
}
}
}