幕布斯6054654
查询的语句:string strConn = "Data Source=.;Initial Catalog=JJking;uid=sa;pwd=12345"; //SQL语言,连接数据库sqlConn.Open(); //打开数据库daEmployees = new SqlDataAdapter("select cEmpId,vEmpName,vAddress,vTelephone,dJoinDate from dbo.Employees where cEmpId='" + strId + "' and dResignationDate is null", sqlConn); //找到相对应的表dsEmployees = new DataSet();daEmployees.Fill(dsEmployees, "表的名字");dgvEmployees.DataSource = dsEmployees.Tables["表的名字"];string strCommand = "select * from dbo.Employees where cEmpId='" + strId + "' and dResignationDate is null";SqlCommand sqlComm = new SqlCommand(strCommand, sqlConn);SqlDataReader sqlDr = sqlComm.ExecuteReader();sqlConn.Close();删除的:SqlConnection sqlConn = new SqlConnection(strConn); //连接数据库的语言上面有SqlConnection sqlConn = new SqlConnection(strConn);string strId = txtId.Text.Trim(); //定义变量string strName = txtName.Text.Trim();string strAddress = txtAddress.Text.Trim();string strTelephone = txtTelephone.Text.Trim();string strJoinDate = txtJoinDate.Text.Trim();string strResignationDate = txtResignationDate.Text.Trim();try{sqlConn.Open();string strCommand = "update dbo.Employees set dResignationDate='" + strResignationDate + "' where cEmpId='" + strId + "'";SqlCommand sqlComm = new SqlCommand(strCommand, sqlConn);int i = (int)sqlComm.ExecuteNonQuery();if (i == 1){daEmployees = new SqlDataAdapter("select * from dbo.Employees where dResignationDate is null", sqlConn);dsEmployees = new DataSet();daEmployees.Fill(dsEmployees, "Employees");dgvEmployees.DataSource = dsEmployees.Tables["Employees"];MessageBox.Show("删除成功!");}写晕了。。。简单点。。。SqlConnection sqlConn = new SqlConnection(strConn);string strCommand = "insert into dbo.Employees(cEmpId,vEmpName,vAddress,vTelephone,dJoinDate,dResignationDate) values('" + strId + "','" + strName + "','" + strAddress + "','" + strTelephone + "','" + strJoinDate + "','" + strResignationDate + "')"; //cEmpId,vEmpName,vAddress....和数据库中表的列对应SqlCommand sqlComm = new SqlCommand(strCommand, sqlConn);int i = (int)sqlComm.ExecuteNonQuery();if (i == 1){daEmployees = new SqlDataAdapter("select * from dbo.Employees ", sqlConn);dsEmployees = new DataSet();daEmployees.Fill(dsEmployees, "Employees");dgvEmployees.DataSource = dsEmployees.Tables["Employees"];MessageBox.Show("添加成功!");}