tags:

views:

30

answers:

2

hi guyz in this method i m just adding the values to the db.

temp is a object. the field value and variables in the object re havin the same name..

dono y this error s comin

plz

help me out...

public virtual void Save_input_parameter_details(Test_Unit_BLL temp )
        {
            SqlConnection con;
            con = new SqlConnection("Data Source=VV;Initial Catalog=testingtool;User ID=sa;Password=sa;");
            con.Open();
            SqlCommand cmd, cmd2, cmd3;
    //try
    //{

            for (int i = 0; i < temp.No_Input_parameters; i++)
            {
                cmd2 = new SqlCommand("insert into Input_parameter_details values(@Input_Parameter_name,@Input_Parameter_datatype,@noparams,@class_code", con);
                cmd2.Parameters.AddWithValue("@Input_Parameter_datatype", temp.Input_Parameter_datatype[i]);
                cmd2.Parameters.AddWithValue("@Input_Parameter_name", temp.Input_Parameter_name[i]);
                cmd2.Parameters.AddWithValue("@noparams", temp.No_Input_parameters);
                cmd2.Parameters.AddWithValue("@class_code",temp.class_code);
                cmd2.ExecuteNonQuery();
            }
        //}
            //catch (Exception ex)
            //    {
            //        MessageBox.Show("error"+ex);
            //    }
        }
A: 

It may be failing based on the unknown actual sequence of columns its trying to push the data into. You are implying the first X number of columns. You may need to be explicit in your SQL such as :

insert into YourTable ( Fld1, Fld2, Fld3 ) values (@ParmVal1, @ParmVal2, @ParmVal3 );

Then do your parameters.add with values... Additionally, you MAY want to make sure your added parameters are in the same sequence as your SQL statement lists them too.

DRapp
A: 

Do the columns in the table line up with the parameters as you have them listed (1st = input_parameter_name, 2nd = input_parameter_datatype, etc.)?

Philip Kelley