c#ExecuteNonQuery: Connection 属性尚未初始化。
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSys...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data;
using System.Data.SqlClient;
public partial class costomera : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("server=localhost;database=BBT;user id=sa;pwd=123");
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void 确定_Click(object sender, EventArgs e)
{
cmd.CommandText = "insert into costomera(customers_id,Placename,credit) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox6.Text + "')";
SqlCommand myCommand = new SqlCommand();
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
cmd.CommandText = "update comstomera(customers_id,Placename,credit)values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox6.Text + "')";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
} 展开
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data;
using System.Data.SqlClient;
public partial class costomera : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("server=localhost;database=BBT;user id=sa;pwd=123");
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void 确定_Click(object sender, EventArgs e)
{
cmd.CommandText = "insert into costomera(customers_id,Placename,credit) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox6.Text + "')";
SqlCommand myCommand = new SqlCommand();
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
cmd.CommandText = "update comstomera(customers_id,Placename,credit)values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox6.Text + "')";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询