ASP.NET C#环境下,添加Access数据库语句总是出错,望高手修改下。。。
OleDbConnectionConn=newOleDbConnection();Conn.ConnectionString="Provider=Microsoft.Je...
OleDbConnection Conn = new OleDbConnection();
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("~/App_Data/sale.mdb");
string aa = TextBox1.Text.Trim();
string bb = TextBox2.Text.Trim();
string cc = TextBox4.Text.Trim();
string dd = TextBox5.Text.Trim();
string ee = TextBox6.Text.Trim();
string ff = TextBox7.Text.Trim();
string gg = TextBox8.Text.Trim();
OleDbCommand cmd = new OleDbCommand( );
cmd.CommandText="insert into member ( username,password,truename,city,postcode,tel,email ) Values ('" +aa+ " ',' " +bb+" ',' " +cc + " ',' " +dd + " ',' " +ee + " ',' " +ff+ " ',' " +gg+ " ' )";
Conn.Open();
cmd.ExecuteNonQuery();
OleDbDataAdapter ada = new OleDbDataAdapter("select * from member ", Conn);
DataSet ds = new DataSet();
ada.Fill(ds, "member");
Conn.Close();
DataBind();
. 展开
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("~/App_Data/sale.mdb");
string aa = TextBox1.Text.Trim();
string bb = TextBox2.Text.Trim();
string cc = TextBox4.Text.Trim();
string dd = TextBox5.Text.Trim();
string ee = TextBox6.Text.Trim();
string ff = TextBox7.Text.Trim();
string gg = TextBox8.Text.Trim();
OleDbCommand cmd = new OleDbCommand( );
cmd.CommandText="insert into member ( username,password,truename,city,postcode,tel,email ) Values ('" +aa+ " ',' " +bb+" ',' " +cc + " ',' " +dd + " ',' " +ee + " ',' " +ff+ " ',' " +gg+ " ' )";
Conn.Open();
cmd.ExecuteNonQuery();
OleDbDataAdapter ada = new OleDbDataAdapter("select * from member ", Conn);
DataSet ds = new DataSet();
ada.Fill(ds, "member");
Conn.Close();
DataBind();
. 展开
4个回答
展开全部
错误提示:System.InvalidOperationException: ExecuteNonQuery: Connection 属性尚未初始化
你的cmd跟Conn没关联起来的缘故。
Conn.Open();之前加上这句:cmd.Connection=Conn;
你的cmd跟Conn没关联起来的缘故。
Conn.Open();之前加上这句:cmd.Connection=Conn;
追问
System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
现在又出现这个状况了,望解答。
追答
cmd.CommandText="insert into member ( username,password,truename,city,postcode,tel,email ) Values ('" +aa+ " ',' " +bb+" ',' " +cc + " ',' " +dd + " ',' " +ee + " ',' " +ff+ " ',' " +gg+ " ' )";
---------->
cmd.CommandText="insert into member ( [username],[password],truename,city,postcode,tel,email ) Values ('" +aa+ " ',' " +bb+" ',' " +cc + " ',' " +dd + " ',' " +ee + " ',' " +ff+ " ',' " +gg+ " ' )";试试
展开全部
cmd.Connection=Conn;
再调试的时候,断点打在 Conn.Open();这句上
看一下 cmd.CommandText 的值 将这个值复制到 查询分析器中 看看哪里语法错了..
看不出来的话 把调试的值 贴上来 我帮你看看
再调试的时候,断点打在 Conn.Open();这句上
看一下 cmd.CommandText 的值 将这个值复制到 查询分析器中 看看哪里语法错了..
看不出来的话 把调试的值 贴上来 我帮你看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
数据库的连接字符串有问题吧。建议输出整段字符串出来看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
错误是啥
追问
错误提示:System.InvalidOperationException: ExecuteNonQuery: Connection 属性尚未初始化。
错误源:cmd.ExecuteNonQuery();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询