Acess添加记录

System.Data.OleDb;

//导入名空间

private Button1_Click(object sender,System.EventArgs e)
{
   if(TextBox1.Text.ToString().Trim()!=""||TextBox1.Text.ToString().Trim()!=String.Empty())
   {
        OleDbConnection con=new OleDbConnection(你的数据库连接);
    //sql语句,往里insert, .... 
        string insertsql="INSERT INTO table_name(column_name) Values(@insert_value)";
        con.Open();
        OleDbCommand cmd=new OleDbCommand(insertsql,con);
        cmd.Parameters.Add("@insert_value",OleDbType.Char,20).Value=TextBox1.Text.ToString().Trim();
        cmd.ExceuteNonQuery();
        con.Close();
    }
}

 

posted @ 2016-06-15 10:57  恋上微笑的天使  阅读(205)  评论(0编辑  收藏  举报