SqlConnection thisConnection=new SqlConnection (@"Server=(local)\ZHENTAI;Integrated Security=true;Connection TimeOut=5;Database=Ticket;");
SqlCommand thisCommand=new SqlCommand ("INSTERT INTO Table1(品名,[规格(KG)],[数量(件)],[单价(元)],合计) Values(@Pm,@Gg,@Sl,@Dj,@Hj");
thisCommand.Parameters .Add ("@Pm",SqlDbType.Text   );
thisCommand.Parameters .Add ("@Gg",SqlDbType.Int );
thisCommand.Parameters .Add ("@Dj",SqlDbType.Int );
thisCommand.Parameters .Add ("@Hj",SqlDbType.Money);
thisConnection.Open ();
thisCommand.Prepare ();
switch((int)numericUpDown1.Value )
{
case 1:
thisCommand.Parameters ["@Pm"]=VarcomboBox.Text;
thisCommand.Parameters ["@Gg"]=numericUpDown2.Value  ;
thisCommand.Parameters ["@Dj"]=domainUpDown2.Text  ;
thisCommand.Parameters ["@Hj"]=Convert.ToDecimal  (textBox1.Text) ;
thisCommand.ExecuteNonQuery ();
break;
case 2:
thisCommand.Parameters ["@Pm"]=VarcomboBox.Text ;
thisCommand.Parameters ["@Gg"]=numericUpDown2.Value  ;
thisCommand.Parameters ["@Dj"]=domainUpDown2.Text  ;
thisCommand.Parameters ["@Hj"]=Convert.ToInt32 (textBox1.Text) ;
thisCommand.ExecuteNonQuery (); thisCommand.Parameters ["@Pm"]=comboBox1.Text;
thisCommand.Parameters ["@Gg"]=numericUpDown3.Value  ;
thisCommand.Parameters ["@Dj"]=domainUpDown1.Text  ;
thisCommand.Parameters ["@Hj"]=Convert.ToInt32 (textBox3.Text) ;
thisCommand.ExecuteNonQuery ();
break;
}

编译后出现:
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1412): 无法将类型“string”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1413): 无法将类型“decimal”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1414): 无法将类型“string”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1415): 无法将类型“decimal”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1419): 无法将类型“string”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1420): 无法将类型“decimal”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1421): 无法将类型“string”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1422): 无法将类型“int”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1425): 无法将类型“string”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1426): 无法将类型“decimal”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1427): 无法将类型“string”隐式转换为“System.Data.SqlClient.SqlParameter”
F:\正太饲料\开票管理软件\开票管理软件测试\开票软件\MainForm.cs(1428): 无法将类型“int”隐式转换为“System.Data.SqlClient.SqlParameter”何解????????????

解决方案 »

  1.   

    晕........我知道了.少一个VALUE
      

  2.   

    改成
    thisCommand.Parameters.Add("Pm", SqlDbType.NVarChar).Value = VarcomboBox.Text;
    thisCommand.Parameters.Add("Pm", SqlDbType.NChar, 8).Value = VarcomboBox.Text;
    之类
      

  3.   

    SqlConnection thisConnection=new SqlConnection (@"Server=(local)\ZHENTAI;Integrated Security=SSPI;Connection TimeOut=5;database=Ticket;");
    thisConnection.Open ();
    //SqlCommand thisCommand=new SqlCommand ("INSERT INTO Table1(品名,规格,数量,单价) VALUES('11111',222,333,444)",thisConnection);


    SqlCommand thisCommand=new SqlCommand ("INSERT INTO Table1(品名,规格,数量,单价,合计) VALUES(@Pm,@Gg,@Sl,@Dj,@Hj",thisConnection);
    thisCommand.Parameters .Add ("@Pm",SqlDbType.VarChar );
    thisCommand.Parameters .Add ("@Gg",SqlDbType.Int);
    thisCommand.Parameters .Add ("@Sl",SqlDbType.Int);
    thisCommand.Parameters .Add ("@Dj",SqlDbType.Money);
    thisCommand.Parameters .Add ("@Hj",SqlDbType.Money );
    //thisCommand.Prepare ();
    switch((int)numericUpDown1.Value )
    {
    case 1: thisCommand.Parameters ["@Pm"].Value =VarcomboBox.Text;
    thisCommand.Parameters ["@Gg"].Value =Convert.ToInt32(numericUpDown2.Value)  ;
    thisCommand.Parameters ["@Sl"].Value =Convert.ToInt32 (domainUpDown2.Text);
    thisCommand.Parameters ["@Dj"].Value =Convert.ToDecimal  (textBox1.Text);
    decimal count=Convert.ToInt32 (domainUpDown2.Text) *Convert.ToDecimal  (textBox1.Text);
    thisCommand.Parameters ["@Hj"].Value =count ;

    thisCommand.ExecuteNonQuery ();

    break;
    case 2:
    /*thisCommand.Parameters ["@Pm"].Value =VarcomboBox.Text ;
    thisCommand.Parameters ["@Gg"].Value =Convert.ToInt32(numericUpDown2.Value)  ;
    thisCommand.Parameters ["@Sl"].Value =Convert.ToInt32(domainUpDown2.Text)  ;
    thisCommand.Parameters ["@Dj"].Value =Convert.ToDecimal (textBox1.Text) ;
    thisCommand.ExecuteNonQuery (); thisCommand.Parameters ["@Pm"].Value =comboBox1.Text;
    thisCommand.Parameters ["@Gg"].Value =Convert.ToInt32(numericUpDown3.Value)  ;
    thisCommand.Parameters ["@Sl"].Value =Convert.ToInt32 (domainUpDown1.Text)  ;
    thisCommand.Parameters ["@Dj"].Value =Convert.ToDecimal (textBox3.Text) ;
    thisCommand.ExecuteNonQuery ();*/
    break;
    case 3:
    break;
    case 4:
    break; }

    这段代码错在哪里?????????????