I am learning C# and I am trying to connect my program to a SQL Server database. For the learning purpose I followed the following video :
http://www.youtube.com/watch?v=Rwdedptaou0
This is my code:
using System.Data.SqlClient;
namespace TestDBMS
{
public partial class MainWindow : Window
{
SqlConnection conn;
SqlCommand cmd;
public MainWindow()
{
InitializeComponent();
conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Reventon\Documents\EmployeeDB.mdf;Integrated Security=True;Connect Timeout=30");
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
string query = "INSERT INTO Table VALUES(3, 'Sachin', '120000', 'Nagaur')";
cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Record Saved");
}
}
}
After compiling the program I am getting an error
Incorrect Syntax Near the 'Table'
(for better representation i have captured the screenshot and uploaded on my Skydrive account). http://sdrv.ms/1bUDe3l
Please help me out.
