asp.net后台管理员代码 能实现简单的修改用户信息和向数据库(Access)中添加题目代码??急!! 5
3个回答
展开全部
string connstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(@".\edu.mdb");
OleDbConnection conn = new OleDbConnection(connstring);
conn.Open();//连接数据库
string sql = "update 学生信息表 set sPassword='" + TextBox3.Text + "' where sName='" + name.ToString() + "' and sPassword='" + TextBox2.Text + "'";//修改(更新)的SQL表达式
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();//修改数据
conn.Cloce();//关闭数据库连接
添加的SQL语句使用Insert语句就行
string connstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(@".\edu.mdb");
OleDbConnection conn = new OleDbConnection(connstring);
conn.Open();
string sql1, sql2, sql;
sql1 = "insert into 学生信息表 (stuID,sName,sSex,sPassword,sDepartment,sMajor";
sql2 = " values ('" + TextBox3.Text.ToString() + "','" + TextBox4.Text.ToString() + "','" + DropDownList2.Text.ToString() + "','" + TextBox5.Text.ToString() + "','" + DropDownList4.Text.ToString() + "','" + DropDownList5.Text.ToString() + "'";
sql = sql1 + ")" + sql2 + ")";
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Cloce();
OleDbConnection conn = new OleDbConnection(connstring);
conn.Open();//连接数据库
string sql = "update 学生信息表 set sPassword='" + TextBox3.Text + "' where sName='" + name.ToString() + "' and sPassword='" + TextBox2.Text + "'";//修改(更新)的SQL表达式
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();//修改数据
conn.Cloce();//关闭数据库连接
添加的SQL语句使用Insert语句就行
string connstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(@".\edu.mdb");
OleDbConnection conn = new OleDbConnection(connstring);
conn.Open();
string sql1, sql2, sql;
sql1 = "insert into 学生信息表 (stuID,sName,sSex,sPassword,sDepartment,sMajor";
sql2 = " values ('" + TextBox3.Text.ToString() + "','" + TextBox4.Text.ToString() + "','" + DropDownList2.Text.ToString() + "','" + TextBox5.Text.ToString() + "','" + DropDownList4.Text.ToString() + "','" + DropDownList5.Text.ToString() + "'";
sql = sql1 + ")" + sql2 + ")";
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Cloce();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询