110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Common;
namespace qqq
{
public partial class dateset : Form
{
public dateset()
{
InitializeComponent();
}
SqlConnection conn;
SqlDataAdapter sda;
DataSet ds;
int m;
private void dateset_Load(object sender, EventArgs e)
{
conn = new SqlConnection("Data Source=.;Initial Catalog=TQMS_QuestionManager;User ID=sa;Password=123");
SqlCommand cmd = new SqlCommand("select * from dbo.TQ_UserInfo", conn);
sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
ds = new DataSet();
sda.Fill(ds, "aaaa");
dataGridView1.DataSource = ds.Tables[0];
bnt2.Visible = false;
groupBox2.Visible = false;
m = 1;
}
private void btn1_Click(object sender, EventArgs e)
{
conn=new SqlConnection("Data Source=.;Initial Catalog=TQMS_QuestionManager;User ID=sa;Password=123");
SqlCommand cmd = new SqlCommand("select * from dbo.TQ_Chapters",conn);
sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
ds = new DataSet();
sda.Fill(ds,"bbb");
dataGridView1.DataSource = ds.Tables[0];
groupBox1.Visible = false;
groupBox2.Visible = true;
btn1.Visible = false;
bnt2.Visible = true;
m = 2;
}
private void update_Click(object sender, EventArgs e)
{
DataTable dt = ds.Tables["aaaa"];
sda.FillSchema(dt, SchemaType.Mapped);
DataRow dr = dt.Rows.Find(TxtID.Text);
dr["TQ_UserName"] = txtName.Text.Trim();
dr["TQ_TureName"]=txtTureName.Text.Trim();
dr["TQ_UserPwd"]=txtPassWord.Text.Trim();
dr["TQ_Email"]=txtEmail.Text.Trim();
dr["TQ_UserType"] = txtUserType.Text.Trim();
SqlCommandBuilder cmdbuilder = new SqlCommandBuilder(sda);
sda.Update(dt);
MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK,MessageBoxIcon.Information);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if(m == 1)
{
TxtID.Text = dataGridView1.SelectedCells[0].Value.ToString();
txtName.Text = dataGridView1.SelectedCells[1].Value.ToString();
txtTureName.Text=dataGridView1.SelectedCells[2].Value.ToString();
txtPassWord.Text = dataGridView1.SelectedCells[3].Value.ToString();
txtEmail.Text = dataGridView1.SelectedCells[4].Value.ToString();
txtUserType.Text = dataGridView1.SelectedCells[5].Value.ToString();
}
else
{
txtChapterID.Text = dataGridView1.SelectedCells[0].Value.ToString();
txtChapterName.Text = dataGridView1.SelectedCells[1].Value.ToString();
txtCourseID.Text = dataGridView1.SelectedCells[2].Value.ToString();
}
}
private void bnt2_Click(object sender, EventArgs e)
{
dateset_Load(sender,e);
btn1.Visible = true;
bnt2.Visible = false;
groupBox1.Visible = true;
groupBox2.Visible = false;
}
}
}