当前位置:编程学习 > C#/ASP.NET >>

提示ExecuteNonQuery()语法错误,是什么原因呢?帮看下

  OleDbConnection conn2 = new OleDbConnection();
            conn2.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source=" + Server.MapPath("App_Data/db1.mdb");
            conn2.Open();

            string strIns = "insert into "+TextBox2.Text+" select * from 图书信息 where 图书编号=" + int.Parse(TextBox1.Text);

            

            OleDbCommand com2 = new OleDbCommand(strIns, conn2);

            com2.ExecuteNonQuery();


            conn2.Close();

           
        } --------------------编程问答-------------------- strIns的内容放在数据库中执行一下看看 --------------------编程问答-------------------- 检查下你的目的表和数据源表的结构一样否 --------------------编程问答-------------------- 数据库测试是成功的。。。 --------------------编程问答--------------------   其他的没问题,你调试下,吧SQL语句,取下来到数据库执行一遍试试。 --------------------编程问答-------------------- 不是用SQL数据库的,是用Access的 --------------------编程问答-------------------- ExecuteNonQuery();不返回任何行
对于 UPDATE、INSERT 和 DELETE 语句,返回值为该命令所影响的行数。如果正在执行插入或更新操作的表上存在触发器,则返回值包括受插入或更新操作影响的行数以及受一个或多个触发器影响的行数。对于所有其他类型的语句,返回值为 -1。如果发生回滚,返回值也为 -1。 --------------------编程问答--------------------
引用 4 楼 menhr 的回复:
  其他的没问题,你调试下,吧SQL语句,取下来到数据库执行一遍试试。


同意,输出sql,先在数据中执行看看 --------------------编程问答-------------------- 表结构一制么? --------------------编程问答-------------------- 都一样的表 --------------------编程问答-------------------- access 不支持楼主的那种写法!! --------------------编程问答-------------------- using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;

namespace 网上书店
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
           
            if((string)(Session["Pass"])!="yes")
            {
                Response.Write("<script language=javascript>alert('您尚未登陆!');</script>");
                Server.Transfer("Default.aspx");
            }
            else
            {
                Page.Title = "欢迎选购!";
                Label1.Text =(string)(Session)["name"];
               }

          
    }

        protected void Button1_Click(object sender, EventArgs e)
        {



            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source=" + Server.MapPath("App_Data/db1.mdb");
            conn.Open();

            string strSql = "Select *from 图书信息 Where 图书编号 =" + int.Parse(TextBox1.Text);
            
            OleDbCommand com = new OleDbCommand(strSql, conn);
            OleDbDataReader dr = com.ExecuteReader();
            GridView2.DataSource = dr;
            //GridView2.DataBind();


            Label2.Text = "您成功选中了一本书!";


            conn.Close();


            OleDbConnection conn2 = new OleDbConnection();
            conn2.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source=" + Server.MapPath("App_Data/db1.mdb");
            conn2.Open();

            string strIns = "insert into "+TextBox2.Text+" select * from 图书信息 where 图书编号=" + int.Parse(TextBox1.Text);

            

            OleDbCommand com2 = new OleDbCommand(strIns, conn2);
            try
            {
                conn.Open();
                com2.ExecuteNonQuery();
                this .
            }

            com2.ExecuteNonQuery();


            conn2.Close();

           
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
           
                     
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Session["pass"] = "yes";
            Response.Redirect("WebForm3.aspx");

        }

        protected void Button4_Click1(object sender, EventArgs e)
        {
            OleDbConnection conn1 = new OleDbConnection();
            conn1.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source=" + Server.MapPath("App_Data/db1.mdb");
            conn1.Open();

            string strCre = " create table " + TextBox2.Text + "(书名 varchar(50),图书编号 int primary key,作者 varchar(30),出版社 varchar(50),图书售价 money,简介 varchar(100))";



            OleDbCommand com1 = new OleDbCommand(strCre, conn1);

            com1.ExecuteNonQuery();


            conn1.Close();


            Session["dingdan"] = TextBox2.Text;
        }
    }
} --------------------编程问答-------------------- using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;

namespace 网上书店
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
           
            if((string)(Session["Pass"])!="yes")
            {
                Response.Write("<script language=javascript>alert('您尚未登陆!');</script>");
                Server.Transfer("Default.aspx");
            }
            else
            {
                Page.Title = "欢迎选购!";
                Label1.Text =(string)(Session)["name"];
               }

          
    }

        protected void Button1_Click(object sender, EventArgs e)
        {



            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source=" + Server.MapPath("App_Data/db1.mdb");
            conn.Open();

            string strSql = "Select *from 图书信息 Where 图书编号 =" + int.Parse(TextBox1.Text);
            
            OleDbCommand com = new OleDbCommand(strSql, conn);
            OleDbDataReader dr = com.ExecuteReader();
            GridView2.DataSource = dr;
            //GridView2.DataBind();


            Label2.Text = "您成功选中了一本书!";


            conn.Close();


            OleDbConnection conn2 = new OleDbConnection();
            conn2.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source=" + Server.MapPath("App_Data/db1.mdb");
            conn2.Open();

            string strIns = "insert into "+TextBox2.Text+" select * from 图书信息 where 图书编号=" + int.Parse(TextBox1.Text);

            

            OleDbCommand com2 = new OleDbCommand(strIns, conn2);
           
            com2.ExecuteNonQuery();


            conn2.Close();

           
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
           
                     
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Session["pass"] = "yes";
            Response.Redirect("WebForm3.aspx");

        }

        protected void Button4_Click1(object sender, EventArgs e)
        {
            OleDbConnection conn1 = new OleDbConnection();
            conn1.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source=" + Server.MapPath("App_Data/db1.mdb");
            conn1.Open();

            string strCre = " create table " + TextBox2.Text + "(书名 varchar(50),图书编号 int primary key,作者 varchar(30),出版社 varchar(50),图书售价 money,简介 varchar(100))";



            OleDbCommand com1 = new OleDbCommand(strCre, conn1);

            com1.ExecuteNonQuery();


            conn1.Close();


            Session["dingdan"] = TextBox2.Text;
        }
    }
} --------------------编程问答-------------------- --------------------编程问答-------------------- 我补充个可能,ACCESS文件写入权限。 --------------------编程问答-------------------- 你的那种写法明显是连接orcle数据库的  你的 连接 字符串 不对
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,