-6

I am trying to add some data into my database. I have 5 columns which all allow null values and all have datatype of varchar. But in my program I am passing only 4 values and fifth column should be empty. When I do this shows error

Number of supplied values does not match in the number of databse columns

How can I add NULL values into database?

My button click

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        string str=mas.empdetedit(ddid.SelectedItem.Text,txtname.Text,txtcon.text,txtval.text);
    }

My class is

public string empdetedit(string id, string name, string con, string val)
{
    string str=insert into table values('"+id+"','"+name+"','"+con+"','"+val+"'");
    conn.nonquery(str);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

2

The syntax to insert into only specific columns of a table is:

INSERT INTO table_name (column1,column2,column3) VALUES (value1,value2,value3)

You are not explicitly specifying the column names, so the database thinks you are giving values for all of them.

Keith
  • 718
  • 8
  • 12