我在aspx建立了两个textbox和一个button,然后准备单机button提交数据写入access的info数据库里德student表里。public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string connStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =E:/info.mdb";    
        
        OleDbConnection myConnection = new OleDbConnection(connStr);
        
  
        string cmd = "INSERT INTO student('"+TextBox1.Text+"','"+TextBox2.Text+"')";        
      
        myConnection.Open();
        
        OleDbCommand myCommand = new OleDbCommand(cmd,myConnection);        myCommand.ExecuteNonQuery();
    }
}运行成功,点击button提交也没问题,但是我打开数据库,里面什么也没有,求教。

解决方案 »

  1.   

    Data Source =E:/info.mdb";你的这个路径对吗?是你虚拟目录下面的吗?加个try..catch..finally,DEBUG调试, F9设置断点调试看看。
    OleDbConnection myConnection=null;
    try
    {
    string connStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =E:/info.mdb"; 
      
      myConnection= new OleDbConnection(connStr);  string cmd = "INSERT INTO student('"+TextBox1.Text+"','"+TextBox2.Text+"')";
      
      myConnection.Open();
       
      OleDbCommand myCommand = new OleDbCommand(cmd,myConnection);  myCommand.ExecuteNonQuery();
    }
    catch(Exception ex)
    {
      throw ex;
    }
    finally
    {
      myConnection.Close();
    }
      

  2.   

    嘿!兄弟:
    insert的语法应该是:
    INSERT INTO  表 (字段1, 字段2) VALUES ('值1','值2')
      

  3.   

    string cmd = "INSERT INTO student('"+TextBox1.Text+"','"+TextBox2.Text+"')";
    这句写错了
    string cmd="INSERT INTO student values('"+TextBox1.Text+"','"+TextBox2.Text+"')";
      

  4.   

    我的insert语法是这么写的啊
    string cmd = "INSERT INTO student('"+TextBox1.Text+"','"+TextBox2.Text+"')";
    因为是所有插入,所以我没写字段了啊我后来改了一下string cmd = "INSERT INTO student(name,gender)VALUES('"+TextBox1.Text+"','"+TextBox2.Text+"')";还是没写进去
      

  5.   

    string cmd = "INSERT INTO student([name],[gender])VALUES('"+TextBox1.Text+"','"+TextBox2.Text+"')";
    连接字符串
      

  6.   

    name为关键字,所以要加个关键字
      

  7.   

    确定执行到按钮事件了吗?
    在Button1_Click的开头加一句
    throw new Exception("进来了");
    看看是什么效果
      

  8.   

    一般不要使用为关键字作为字段名称
    ACCESS数据库的字段最好用[]-->[字段名]