string connection = "Provider=Microsoft.ACE.OLEDB.12.0 ;" + "Data Source=D:\\it101\\LoginForm\\App_Data\\registration.mdb";
string query = "INSERT INTO registration values (adsdsa,adsadsa,87987,dasdsa)";
OleDbConnection con = new OleDbConnection(connection);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = query;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter(query,con);
DataSet ds =new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
答案 0 :(得分:1)
用于插入
string queryString = "INSERT INTO registration values ('adsdsa','adsadsa',87987,'dasdsa')";
using (OleDbConnection connection = new OleDbConnection(connection))
using (OleDbCommand command = new OleDbCommand(queryString, connection))
{
connection.Open();
command.ExecuteNonQuery();
}
加载数据时
using(OleDbConnection con = new OleDbConnection(connection))
using(var adapter = new OleDbDataAdapter("select * from registration", con)
{
DataSet ds =new DataSet();
adapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
答案 1 :(得分:1)
你需要引用你的字符串值 -
string query = "INSERT INTO registration values ('adsdsa','adsadsa',87987,'dasdsa')";
答案 2 :(得分:1)
使用此
更改插入行string query = "INSERT INTO registration values ('adsdsa','adsadsa',87987,'dasdsa')";
答案 3 :(得分:0)
连接后打开();
添加此内容 cmd.open(); cmd.ExecuteNonQuery();
表示将数据传递给值时添加这样的引号 插入表名值('data1','data2') 我希望这能帮到您。
答案 4 :(得分:0)
请你试试这个:
string query = "INSERT INTO registration values ('adsdsa','adsadsa',87987,'dasdsa');
希望这会有所帮助..