SQL=“Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,MEMO,ISGROUP) Values('"+1016+"'﹐'"+jcy+"','"+jcy+"','"+jcy+"','"+jcy+"','"+jcy+"','"+jcy+"','"+68764+"','"+657646+"','"+jcy+"',0)”;

解决方案 »

  1.   

    设个断点,看看sql语句变了没有?
      

  2.   

    我是从断点取的SQL语句,没变,能上ACCESS数据库中执行的!但,就是不知到问题出在哪?上面的那位兄弟(啊丸)写的SQL好象不对!我试了!
      

  3.   

    SQL=“Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,MEMO,ISGROUP) Values(1016﹐'"+jcy+"','"+jcy+"','"+jcy+"','"+jcy+"','"+jcy+"','"+jcy+"','"+68764+"','"+657646+"','"+jcy+"',0)”;第一個是數字型﹐沒有注意
    現在應該可以了
      

  4.   

    还是不行,jcy是要插入的值,你用加号连接就变成变量了!所以......
    好象还是不行,真是麻烦你了!
      

  5.   

    應該沒用問題啊
    我剛才做了個試驗
    string strcomm1="insert into Student(Studentid,Grade,LastName,FirstName)Values('100','1','1','1')";
    沒什么錯﹐很好啊
      

  6.   

    我是遮掩做的public void CreateMyOleDbCommand(string myExecuteQuery, string myConnectionString) 
    {
      try
       {
         DataSet ds=new DataSet();
         OleDbConnection myConnection = new OleDbConnection(myConnectionString);
         SqlDataAdapter adp=new SqlDataAdapter(myExecuteQuery, myConnection);
         adp.Fill(ds);
        }
      catch(Exception Ex)
       {
         throw Ex;
       }
    }
      

  7.   

    什么是遮掩做的???
    你的这段代码我考过来用
    SqlDataAdapter adp=new SqlDataAdapter(myExecuteQuery, myConnection);
    出错,告诉我myConnection类型不对!
    你好象引用了using System.Data.SqlClient;
    不用引用这个类能解决吗?
      

  8.   

    String SQLStr=SQL上面的SQL语句;
    public void CreateMyOleDbCommand(string myExecuteQuery, string myConnectionString) 
    {
    try
    {
    OleDbConnection myConnection = new OleDbConnection(myConnectionString);
                                        myConnection.Open();
    OleDbCommand myCommand = new OleDbCommand(myExecuteQuery, myConnection);
    myCommand.ExecuteNonQuery();
    myConnection.Close();
    }
    catch(Exception Ex)
    {
    throw Ex;
    }
    }
      

  9.   

    不行呀!我都急死了!!!
    老是出错呀!一执行到myCommand.ExecuteNonQuery();就出错!是不是C#有什么BUG呀那位高手在帮着看看!我在线等!!!
      

  10.   

    我用Access插入数据,没有问题,一定是你的语句有错误,贴出你的全部代码和错误提示在看看
      

  11.   

    首先检查类型是不是匹配,如果你认为没问题,同意楼上的写的Select 格式,比如字符型药用'"+xyz+"',其他的"+xyx+",好像不是应该是其他的问题,更别说是C#的BUG......
      

  12.   

    我的全部代码如下:可以拷贝试一试!谢谢
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.OleDb;namespace Contest
    {
    /// <summary>
    /// MainForm 的摘要说明。
    /// </summary>
    public class MainForm : System.Windows.Forms.Form
    {
    private OleDbConnection cnn=pool.getConnection();
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.TabControl tabControl1;
    private System.Windows.Forms.TabPage Ex1;
    private System.Windows.Forms.TabPage Ex3;
    private System.Windows.Forms.TextBox vSQL;
    private System.Windows.Forms.TextBox vInnerex;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public MainForm()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    this.tabControl1 = new System.Windows.Forms.TabControl();
    this.Ex1 = new System.Windows.Forms.TabPage();
    this.vSQL = new System.Windows.Forms.TextBox();
    this.Ex3 = new System.Windows.Forms.TabPage();
    this.vInnerex = new System.Windows.Forms.TextBox();
    this.tabControl1.SuspendLayout();
    this.Ex1.SuspendLayout();
    this.Ex3.SuspendLayout();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(152, 256);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(72, 40);
    this.button1.TabIndex = 0;
    this.button1.Text = "TEST";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // tabControl1
    // 
    this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.Ex1,
      this.Ex3});
    this.tabControl1.Dock = System.Windows.Forms.DockStyle.Top;
    this.tabControl1.Name = "tabControl1";
    this.tabControl1.SelectedIndex = 0;
    this.tabControl1.Size = new System.Drawing.Size(504, 248);
    this.tabControl1.TabIndex = 2;
    // 
    // Ex1
    // 
    this.Ex1.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.vSQL});
    this.Ex1.Location = new System.Drawing.Point(4, 21);
    this.Ex1.Name = "Ex1";
    this.Ex1.Size = new System.Drawing.Size(496, 223);
    this.Ex1.TabIndex = 0;
    this.Ex1.Text = "SQL";
    // 
    // vSQL
    // 
    this.vSQL.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.vSQL.Dock = System.Windows.Forms.DockStyle.Fill;
    this.vSQL.Multiline = true;
    this.vSQL.Name = "vSQL";
    this.vSQL.Size = new System.Drawing.Size(496, 223);
    this.vSQL.TabIndex = 2;
    this.vSQL.Text = "";
    // 
    // Ex3
    // 
    this.Ex3.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.vInnerex});
    this.Ex3.Location = new System.Drawing.Point(4, 21);
    this.Ex3.Name = "Ex3";
    this.Ex3.Size = new System.Drawing.Size(496, 223);
    this.Ex3.TabIndex = 2;
    this.Ex3.Text = "InerExce";
    // 
    // vInnerex
    // 
    this.vInnerex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.vInnerex.Dock = System.Windows.Forms.DockStyle.Fill;
    this.vInnerex.Multiline = true;
    this.vInnerex.Name = "vInnerex";
    this.vInnerex.Size = new System.Drawing.Size(496, 223);
    this.vInnerex.TabIndex = 3;
    this.vInnerex.Text = "";
    // 
    // MainForm
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(504, 301);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.tabControl1,
      this.button1});
    this.Name = "MainForm";
    this.Text = "MainForm";
    this.tabControl1.ResumeLayout(false);
    this.Ex1.ResumeLayout(false);
    this.Ex3.ResumeLayout(false);
    this.ResumeLayout(false); }
    #endregion
    [STAThread]
    static void Main() 
    {

    Application.Run(new MainForm());
    } private void button1_Click(object sender, System.EventArgs e)
    {
    try
    {
    String ConStr="Provider = Microsoft.Jet.OLEDB.4.0;Data Source =Jcy.mdb";
    String SQLStr="Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,MEMO,ISGROUP) Values(1016,'jcy','jcy','jcy','jcy','jcy','jcy','68764','657646','jcy',0)";
    this.vSQL.Text=SQLStr;
    this.CreateMyOleDbCommand(SQLStr,ConStr);
    }
    catch
    {
    }
    }
     
    public void CreateMyOleDbCommand(string myExecuteQuery, string myConnectionString) 
    {
    try
    {
    OleDbConnection myConnection = new OleDbConnection(myConnectionString);
    OleDbCommand myCommand = new OleDbCommand(myExecuteQuery, myConnection);
    myCommand.Connection.Open();
    myCommand.ExecuteNonQuery();
    myConnection.Close();
    }
    catch(Exception Ex)
    {
    // throw Ex;
    this.vInnerex.Text=Ex.ToString();
    }
    }
    }
    }
    运行后点测试,SQL和错误会显示的
    数据库可以自己按我第一次发的建立,我的ID是插入的,不是自动增加的!
      

  13.   

    我按照你的建了个表,在Access中运行完全没有问题
    在Sql Server中运行,有关键字问题
      

  14.   

    是的,在ACCESS中运行是没问题!
    问题是在C#中运行就出现了问题呀,而且是在提交的时候出错的
    ————————————————————————————————————
    “首先检查类型是不是匹配,如果你认为没问题,同意楼上的写的Select 格式,比如字符型药用'"+xyz+"',其他的"+xyx+",好像不是应该是其他的问题,更别说是C#的BUG......”楼上说的我试过了,还是不行“'"+xyz+"'”这样的写法有错误,这样xyz会变成变量,而不是要存入的值了
      

  15.   

    返回影响的行数(int型)
    我也试过,不过也不行,返回是0,正常返回1的
      

  16.   

    应该是SQL语句的问题你在表中定义ID和ISGROUP为数字型如果是带小数的话"Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,MEMO,ISGROUP) Values(1016,'jcy','jcy','jcy','jcy','jcy','jcy','68764','657646','jcy',0)"是不会对的,你可以试着把要插入的数字给single变量。然后在插入!不过可能还是不对我不敢肯定你自己试试。
      

  17.   

    huhong你说的有点错误,ID只能是大于或等于0的整数,ISGROUP只能是0或是1
    没有带小数的可能!况且
    "Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,MEMO,ISGROUP) Values(1016,'jcy','jcy','jcy','jcy','jcy','jcy','68764','657646','jcy',0)"
    这句SQL语句保存到一个String的变量中
    ——————————BILLZXH在线等回复
      

  18.   

    很急啊?哈哈!找到你的错误了。在你SQL语句。你应该写成:
    "Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,[MEMO],ISGROUP) Values(1016,'jcy','jcy','jcy','jcy','jcy','jcy','68764','657646','jcy',0)"
    看明白了没MEMO是ACCESS数据库的默认关键字你应该把这个字段名改了。不过不改按我的做也对。