Invalid column name sql error

后端 未结 11 1212
梦毁少年i
梦毁少年i 2020-11-30 03:16

I am trying to enter data into my database, but it is giving me the following error:

Invalid column name

Here\'s my code

<
11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 04:20

    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

提交回复
热议问题