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();
}
} 展开
展开全部
楼主没把 SqlConnection 对象传给SqlCommand。
加一句
cmd.Connection=conn;
加一句
cmd.Connection=conn;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
启帆信息
2024-11-19 广告
2024-11-19 广告
启帆信息是英伟达中国区代理商,原厂授权代理,提供全面的软件技术解决方案以及NVIDIA以太网产品、交换机等产品,欢迎前来咨询!...
点击进入详情页
本回答由启帆信息提供
2011-06-16
展开全部
一楼说的没错,支持!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询