/// <summary>
        /// 建立K3数据库连接
        /// </summary>
        /// <returns>返回SqlConnection对象</returns>
        public SqlConnection getK3con()
        {
            string str = "server = (local);database = ais20090413161510;trusted_connection = yes";
            SqlConnection conn = new SqlConnection(str);
            return conn;
        }
        /// <summary>
        /// 执行SqlCommand命令(K3)
        /// </summary>
        /// <param name="str">SQL语句</param>
        public void getK3com(string str)
        {
            SqlConnection mycon = this.getK3con();
            mycon.Open();
            SqlCommand mycom = new SqlCommand(str, mycon);
            mycom.ExecuteNonQuery();
            mycom.Dispose();
            mycon.Close();
            mycon.Dispose();
        }
   string sqlInst = "insert into icstockbill(fbrno,finterid,ftrantype,fdate,fbillerno,fsupperid,ffmanager,fsmanager,fbillerid,fpostyle,fheadselfA0140,fheadselfA0141,fheadselfA0142,fheadselfA0143)  values (0,'" + tbx_FinterId + "',1,'" + dtp_fdate + "','" + tbx_tvid + "','" + tbx_supplyid + "','" + tbxBillerid + "','" + tbxBillerid + "','" + tbxBillerid + "','" + tbx_postyle + "','" + tbx_czbh + "','" + tbx_chbh + "','" + tbx_pzsj + "','" + tbx_pzsby + "') ";
                                decimal count = Convert.ToDecimal(tbx_netweight.Text.Trim());
                                decimal price = Convert.ToDecimal(dr["classprice_1"].ToString());
                                decimal netamount = count * price;
                                tbx_netAmount.Text = netamount.ToString();
                                tbx_netprice.Text = dr["classprice_1"].ToString();
                                tbx_Class.Text = "一级";
                                //SqlCommand cmd =SClass.getK3com(sqlInst);
                                SqlCommand cmd = new SqlCommand();
                                cmd = SClass.getK3com(sqlInst);

                                MessageBox.Show("等级:一级 已入库。");错误 1 无法将类型“void”隐式转换为“System.Data.SqlClient.SqlCommand” F:\C#(二次开发)案例\天菊项目100120\Prgram_TJV1.0\Prgram_TJV1.0\FrmCheck.cs 177 39 Prgram_TJV1.0asking...........

解决方案 »

  1.   

    日 getK3com 返回的是啥类型啊 你赋值给sqlcommand
      

  2.   

    你调用的public void getK3com(string str) 
            { 
                SqlConnection mycon = this.getK3con(); 
                mycon.Open(); 
                SqlCommand mycom = new SqlCommand(str, mycon); 
                mycom.ExecuteNonQuery(); 
                mycom.Dispose(); 
                mycon.Close(); 
                mycon.Dispose(); 
            } 
    没有返回值!!
      

  3.   

    SqlCommand cmd = new SqlCommand(); 
    cmd = SClass.getK3com(sqlInst); 
    改成:
    SClass.getK3com(sqlInst);
    或者修改 public void getK3com(string str)为
    public SqlCommand getK3com(string str),在里面返回SqlCommand。你把getK3com的屁股堵住了还让它拉屎怎么行?
      

  4.   

    getK3com返回是void类型public void getK3com(string str) 
            { 
                SqlConnection mycon = this.getK3con(); 
                mycon.Open(); 
                SqlCommand mycom = new SqlCommand(str, mycon); 
                return mycom ;
            } 
      

  5.   

    SClass.getK3com(sqlInst); 晕,你方法里返回是VOID的类型呀,改成public SqlCommand getK3com(string str) 
            { 
                SqlConnection mycon = this.getK3con(); 
                mycon.Open(); 
                SqlCommand mycom = new SqlCommand(str, mycon); 
                return mycom ; 
            } 
      

  6.   

      SqlCommand cmd = new SqlCommand();
      cmd = SClass.getK3com(sqlInst); 
    ===》
    改成:SClass.getK3com(sqlInst);