ExecuteNonQuery: connection 属性尚未初始化 insert into YX_Shoping (YX_Size,YX_Company,YX_OrderID,YX_User,YX_ProBianMa,YX_ProName,YX_ProID,YX_OrderProNum,YX_Price,YX_ShopPrice,YX_OrderAddtime,YX_Unit)Values (
会员订购的时候点下一步按钮对应这里 protected void Button1_Click1(object sender, EventArgs e)没有问题,但不是会员就出现如上错误,怎么感觉不是会员没有那些字段还是什么的.刚来的没有多少分..
先谢谢了....
整页的代码我都贴出来....
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class BasketNext : System.Web.UI.Page
{
    YX_sql exsql = new YX_sql();    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["myCartTable"] != null)
            {
                DataTable nowTable3 = new DataTable("nowCartTable3");
                nowTable3 = (DataTable)Session["myCartTable"];
                if (nowTable3.Rows.Count <= 0)
                {
                    ChangeHope_fc.Show_Msg("You have not ordered merchandise");
                    Response.End();
                }
            }
            else
            {
                ChangeHope_fc.Show_Msg("You have not ordered merchandise", "Default.aspx");
                Response.End();
            }
            if (Session["username"] != null)
            {
                binduser(Session["username"].ToString());
            }
            
            if (!IsPostBack)
            {
                InitData();
                ViewShoppingCart();
                Caculator();
            }
        }
        catch (Exception ee)
        {
            Response.Write(ee.Message);
        }
    }
        /// <summary>
    /// 绑订接货人信息
    /// </summary>
    /// <param name="username"></param>
    private void binduser(string username)
    {
        exsql.Open();
        string sql = "Select * from YX_UserInfo where YX_User='" + username + "'";
        OleDbDataReader dr = exsql.Re_dr(sql);        if (dr.Read())
        {
            this.TextBox1.Text = dr["YX_ProductPerson"].ToString();
            this.TextBox2.Text = dr["YX_ProductAddr"].ToString();
            this.TextBox5.Text = dr["YX_ProductEmail"].ToString();
            this.TextBox4.Text = dr["YX_ProductTel"].ToString();
            this.TextBox3.Text = dr["YX_ProductCode"].ToString();
            this.TextBox7.Text = dr["YX_Company"].ToString();
        }        dr.Close();
        exsql.Close();
    }
    public void Caculator()
    {
        if (Session["myCartTable"] != null)                         //购物车是否为空
        {
            int h;
            Double TotalPri;
            TotalPri = 0;
            DataTable nowTable3 = new DataTable("nowCartTable3");
            nowTable3 = (DataTable)Session["myCartTable"];
            if (nowTable3.Rows.Count > 0)                               //返回购物车中是否有货物
            {
                for (h = 0; h <= nowTable3.Rows.Count - 1; h++)
                {
                    TotalPri = TotalPri + Convert.ToDouble(nowTable3.Rows[h]["TotalPrice"]);                }
                label.Text = "Total: " + C1Round(TotalPri, 1).ToString() + " ";
            }
        }    }
    public double C1Round(double value, int digit)
    {
        double vt = Math.Pow(10, digit);
        double vx = value * vt;        vx += 0.5;
        return (Math.Floor(vx) / vt);
    }
    public void ViewShoppingCart()
    {
        if (Session["myCartTable"] != null)
        {
            ///////////////////////检查库存
            DataTable checkTable = (DataTable)Session["myCartTable"];
            DataRow checkDR;
            int pn = checkTable.Rows.Count;
            int j = 0;
            while (j < pn)
            {
                checkDR = checkTable.Rows[j];
                checkkc(Convert.ToInt16(checkDR[0]), Convert.ToInt16(checkDR["YX_OrderProNum"]));
                j++;
            }
            ///////////////////////
            DataTable viewTable = new DataTable("nowCartTable");
            viewTable = (DataTable)Session["myCartTable"];
            this.ShopCart.DataSource = viewTable.DefaultView;         //购物车绑定
            this.ShopCart.DataBind();
        }
    }
    
    protected void Button1_Click1(object sender, EventArgs e)
    {
string sql ="";
        try
        {
            if (this.TextBox1.Text == "")
            {
                Response.Write("<script>alert('Please enter the Consignee Name!');history.back();</script>");
            }
            if (this.TextBox7.Text == "")
            {
                Response.Write("<script>alert('Please enter the Company!');history.back();</script>");
            }
            if (this.TextBox2.Text == "")
            {
                Response.Write("<script>alert('Please enter the Address!');history.back();</script>");
            }
            if (this.TextBox3.Text == "")
            {
                Response.Write("<script>alert('Please enter the Postcode!');history.back();</script>");
            }
            if (this.TextBox4.Text == "")
            {
                Response.Write("<script>alert('Please enter the Telephone!');history.back();</script>");
            }
            if (this.TextBox5.Text == "")
            {
                Response.Write("<script>alert('Please enter the Email!');history.back();</script>");
            }
            //////////写进定单表                        //订单号
            string sj = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.TimeOfDay.Hours.ToString() + DateTime.Now.TimeOfDay.Minutes.ToString() + DateTime.Now.TimeOfDay.Milliseconds.ToString();
            ////把订购商品写进订购商品表
            sql = " insert into YX_Shoping (YX_Size,YX_Company,YX_OrderID,YX_User,YX_ProBianMa,YX_ProName,YX_ProID,YX_OrderProNum,YX_Price,YX_ShopPrice,YX_OrderAddtime,YX_Unit)";
            sql = sql + " values(";            OleDbCommand comm = new OleDbCommand();
            comm.Connection = exsql.con;
            DataTable nowTable = (DataTable)Session["myCartTable"];
            DataRow oldDR;            if (Session["myCartTable"] == null || Session["myCartTable"].ToString() == "")
            {
                ChangeHope_fc.Show_Msg("Please select the product", "Default.aspx");
                Response.End();
            }
            else
            {
                int pn = nowTable.Rows.Count;
                int i = 0;
                while (i < pn)
                {
    string stt="",stl="";
                    oldDR = nowTable.Rows[i];
                    DataRow dr = dtable(Convert.ToInt16(oldDR["YX_ProID"]));                    stt += "'" + oldDR["YX_Size"].ToString() + "','";
                    stt += this.TextBox7.Text + "','";
                    stt += sj + "','";
                    stt += this.TextBox1.Text + "','";
                    stt += dr["YX_BMa"].ToString() + "','";
                    stt += dr["YX_ProductName"].ToString() + "',";
                    stt += Convert.ToInt16(dr["YX_ID"]).ToString() + ",";
                    stt += Convert.ToInt16(oldDR["YX_OrderProNum"]).ToString() + ",";
                    stt += Convert.ToDouble(oldDR["YX_Price"]).ToString() + ",";
                    stt += Convert.ToDouble(oldDR["YX_ShopPrice"]).ToString() + ",'";
                    stt += DateTime.Now.ToString() + "','";
                    stt += Session["RateFuhao"].ToString() + "')";
                    exsql.Open();
    stl=sql+stt;
                    comm.CommandText = stl;
                    comm.ExecuteNonQuery();
                    i++;
                }                ////
                ////写入订单
                sql = "insert into YX_OrderForm (YX_Company,YX_OrderFormID,YX_OrderUser,YX_SumPrice,YX_OrderDate,YX_RGoodsUser,YX_RGoodsEmail,YX_RGoodsTel,YX_RGoodsAddr,YX_RGoodsCode,YX_RGoodsFY,YX_DGoodsPrice,YX_PaymentPrice,YX_Uint) values ";
                OleDbCommand com = new OleDbCommand();                sql += "('" + this.TextBox7.Text + "','";
                sql += sj + "','";
                sql += Session["username"].ToString() + "','";
                sql += sumprice() + "','";
                sql += DateTime.Now.ToString() + "','";
                sql += this.TextBox1.Text + "','";
                sql += this.TextBox5.Text + "','";
                sql += this.TextBox4.Text + "','";
                sql += this.TextBox2.Text + "','";
                sql += this.TextBox3.Text + "','";
                sql += this.TextBox6.Text + "',";
                sql += 1.0 + ",";
                sql += 0 + ",'";
                sql += Session["RateName"].ToString() + "')";
exsql.Open();
                com.Connection = exsql.con;
                com.CommandText = sql;
                com.ExecuteNonQuery();
                Response.Redirect("OrderOk.aspx?order=" + sj);
                Response.End();
            }
        }
        catch (Exception ee)
        {
            ChangeHope_fc.Show_Msg(ee.Message+sql);
        }    }
    public DataRow dtable(int YX_ID)
    {        exsql.Open();
        OleDbDataAdapter com = new OleDbDataAdapter("select * from YX_Product where YX_ID=" + YX_ID, exsql.con);
        DataSet ds = new DataSet();
        com.Fill(ds, "temp2");
        exsql.Close();
        return ds.Tables["temp2"].Rows[0];
    }
    

解决方案 »

  1.   

    mycom = New System.Data.SqlClient.SqlCommand("update test set name='" & name.Text & "' where id='" & sid & "'",mycon)
      

  2.   

    mycom = New System.Data.SqlClient.SqlCommand("update test set name='" & name.Text & "' where id='" & sid & "'",mycon) 这句要放在哪里? ^_^
      

  3.   

    exsql.con如何定义的
    OleDbCommand cmd = new OleDbCommand();
     using (OleDbConnection conn = new OleDbConnection(connectionString))
     {
    }
      

  4.   

    exsql.Open(); 
                    com.Connection = exsql.con; 
                    com.CommandText = sql; 
                    com.ExecuteNonQuery(); 
                    Response.Redirect("OrderOk.aspx?order=" + sj); 
                    Response.End(); 
    调下位置
     com.Connection = exsql.con; 
    exsql.Open();    
        [align=left]com.CommandText = sql; 
                    com.ExecuteNonQuery(); 
                    Response.Redirect("OrderOk.aspx?order=" + sj); 
                    Response.End(); [/align]