C#中修改数据库,怎么操作的呢?
这些代码是读取数据库的表,那么如果要在C#中修改,添加..怎么弄了...?
private void button1_Click(object sender, EventArgs e)
{
string connectString = this.txtConn.Text.Trim();//数据库连接字符串,用一个字符窜来接受txt中的文本
SqlConnection con = new
System.Data.SqlClient.SqlConnection(connectString);//创建一个连接对象
con.Open();//打开连接
SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand();//创建一个Command对象
sqlCmd.Connection = con;
sqlCmd.CommandText = "SELECT * FROM booktable ";//sql语句
System.Data.SqlClient.SqlDataAdapter sqlAdapter = new System.Data.SqlClient.SqlDataAdapter(sqlCmd);
DataTable table = new DataTable();
sqlAdapter.Fill(table);//填充数据到表格;
this.dataGridView1.DataSource = table;//给GridView控制数据源赋值
con.Close();//(联接结束)
}
------解决方案--------------------insert
update
or
dataapter
------解决方案--------------------private void toolDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show( "确定删除? ", "系统提示 ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
string sql = "DELETE FROM SYSRULE WHERE ID_RULE=@ID_RULE ";
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandText = sql;
sqlCmd.Parameters.Add(new SqlParameter( "@ID_RULE ", this.dtRule.Rows[bind.Position][ "ID_RULE "]));
this.dataAccess.ExecuteSql(sqlCmd);
this.dtRule.Rows.RemoveAt(bind.Position);
}
}
================================================
if (CheckData())
{
MessageBox.Show( "数据检查失败! ", "系统提示 ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
SqlCommand sqlCmd = new SqlCommand();
string sql;
if (FormStatus