what error did you get? is the path to the database corrrect? if you are using ASP.NET, you need to use Server.MapPath, if you are using winform, you need to use Application.StartupPath before the db file name:string strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mmedia.mdb";
also use a parameterized query instead, or try string strInsert = " INSERT INTO userinfo ( username , callnum , useradress , usertype , creatdate ) VALUES ( '" ;
strInsert += textBox1.Text + "', '" ;
strInsert += textBox2.Text + "', '" ;
strInsert += textBox3.Text + "', '" ;
strInsert += textBox4.Text + "', '" ;
strInsert += textBox5.Text + "')" ;

解决方案 »

  1.   

    INSERT INTO userinfo ( username , callnum , useradress , usertype , creatdate )最后一个是时间型吧,你只记录:textBox5.Text 字符串?Access里面要使用这样:
    #1992-9-9#所以代码:strInsert += textBox5.Text + ")" ;
    应该这样
    strInsert += "#";
    strInsert += textBox5.Text;
    strInsert += "#";
    strInsert += " )"
      

  2.   

    谁能介绍,具体的INSERT 怎么写?不考虑数据类型,假设都是字符型
    的。
      

  3.   

    insert into databasename(column1,column2...) values(value1,value2...)
      

  4.   

    对,好像这里你忘了单引号string strInsert = " INSERT INTO userinfo ( username , callnum , useradress , usertype , creatdate ) VALUES ( '" ;思归的应该是正确的
      

  5.   

    "insert into userTable(a1,a2,a3) values ('" + 
     TextBox1.Text +  "','" + TextBox2.Text + "','" + TextBox3.Text + "')"
      

  6.   

    格式应该象why168说得那样吧?可是我运行的结果是“未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 system.data.dll 中“。
      

  7.   

    影响我学习进度,这个如何是好?重新修改了一下,我把ACCESS数据库字段全部改成文本的,还是不行,错误信息如下:System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
       at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
       at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
       at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
       at UserManager.Form3.button1_Click(Object sender, EventArgs e) in e:\vc++\usermanager\form3.cs:line 245。

    private void button1_Click(object sender, System.EventArgs e)
    {
    try
    {
    if (textBox1.Text!=""&&textBox2.Text!=""&&textBox3.Text!=""&&textBox4.Text!=""&&textBox5.Text!="")
    {
    string T_str="Provider =Microsoft.Jet.OLEDB.4.0;Data Source=mmedia.mdb";
    OleDbConnection T_conn=new OleDbConnection(T_str);
    T_conn.Open();
    string T_insert="Insert into userinfo(username,callnum) Value('" +textBox1.Text+ "','" +textBox2.Text+ "')";
    OleDbCommand T_command=new OleDbCommand(T_insert,T_conn);
    T_command.ExecuteNonQuery();
    T_conn.Close();
    Label lb1=new Label();
    lb1.Location=new Point(button1.Location.X,button1.Location.Y-10);
    lb1.ForeColor=Color.Red;
    lb1.Text="你已经成功的添加了数据!";
    this.Controls.Add(lb1);
    textBox1.Text="";
    textBox2.Text="";
    textBox3.Text="";
    textBox4.Text="";
    textBox5.Text="";
    }
    else 
    MessageBox.Show("必须填满所有字段值","错误!"); }
    catch(Exception ed)
    {
    MessageBox.Show("保存数据记录发生错误"+ed.ToString(),"错误!");
    }
    }
      

  8.   

    it 's "values" not "value"!!!!!!!!!!
    呵呵,揭帖,都有份。