I am trying to enter data into my database, but it is giving me the following error:
Invalid column name
Here\'s my code
<
first create database name "School" than create table "students" with following columns 1. id 2. name 3. address
now open visual studio and create connection:
namespace school { public partial class Form1 : Form { SqlConnection scon; public Form1() { InitializeComponent(); scon = new SqlConnection("Data Source = ABC-PC; trusted_connection = yes; Database = school; connection timeout = 30"); } //create command SqlCommand scom = new SqlCommand("insert into students (id,name,address) values(@id,@name,@address)", scon); //pass parameters scom.Parameters.Add("id", SqlDbType.Int); scom.Parameters["id"].Value = textBox1.Text; scom.Parameters.Add("name", SqlDbType.VarChar); scom.Parameters["name"].Value = this.textBox2.Text; scom.Parameters.Add("address", SqlDbType.VarChar); scom.Parameters["address"].Value = this.textBox6.Text; scon.Open(); scom.ExecuteNonQuery(); scon.Close(); reset(); }
also check solution here: http://solutions.musanitech.com/?p=6