1、 if (radioManage.Checked = true) string strcon = Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True; /连接数据库的字符串,用于指定数据库地址,名称,账号,密码,连接方式 SqlConnection sqlCon = new SqlConnection(strcon); /实例化并定义一个数据库连接 sqlCon.Open(); /打开数据库连接 string sql = select * from login where usernum=usernum an
2、d userpassword=suerpassword /定义要查询sql语句 SqlCommand cmd = new SqlCommand(sql, sqlCon); /实例化并定义sql语句和数据库路径 cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); /定义cmd查询命令的字段属性,loginname sqldbtype nchar(20)suerpassword /同上 cmd.Parameters.Value = username.Text; /将username中的text保存到变量loginname.Value = passwo
3、rd.Text; SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read() this.Visible=false; Form2 Formmain = new Form2(); /应该是实例化一个主窗体的 this.Hide(); /应该是切换到主窗口的或关闭自己的 Formmain.Show(); /应该是打开一个主窗体的 dr.Close();/关闭dr的数据库连接 else / if (dr.Read()读取失败则执行如下代码 MessageBox.Show(密码错误,请重新输入! /显示提示信息 else if (radioPerson.
4、Checked=true) string sql1 = select * from reader where usernum=usernum and userpassword=suerpassword SqlCommand cmd1 = new SqlCommand(sql1, sqlCon); cmd1.Parameters.Add( cmd1.Parameters cmd1.CommandText=sql1; SqlDataReader dr = cmd1.ExecuteReader(); if (dr.Read() Form9 Formmain = new Form9(); else M
5、essageBox.Show(用户名或密码错误警告 else没有选择角色, 添加图书代码SqlConnection sqlcon = new SqlConnection( string str = insert into dbo.book values(bnum,bname,bauthor,bpublic,bclasses,benshu) sqlcon.Open(); SqlCommand cmd = new SqlCommand(str, sqlcon);bnumbnamebauthorbpublicbclassesbenshu, SqlDbType.TinyInt);.Value = bn
6、um.Text;.Value = bname.Text;.Value = bauthor.Text;.Value = bpublic.Text;.Value = bclasses.Text;.Value = benshu.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); this.bnum.Clear(); this.bname.Clear(); this.bauthor.Clear(); this.bpublic.Clear(); this.benshu.Clear(); this.bclasses.Clear();添加成功!删除图书代码Integra
7、ted Security=Truedelete from book where bnum=bnum.Value = this.tnum.Text; this.tnum.Clear(); this.tno.Clear(); this.tname.Clear(); this.tpublisher.Clear(); this.tauthor.Clear(); this.tclasses.Clear(); this.tbenshu.Clear();删除成功!查询图书代码SqlConnection con = new SqlConnection();/建立数据库连接 con.ConnectionStri
8、ng = con.Open();/打开连接 SqlCommand cmd = new SqlCommand(select * from book where bname=bname, con);.Value = bookname.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(图书记录表 da.TableMappings.Add(BorrowRecord借阅记录表 da.TableMappings0.ColumnMappings.Add(图书号图书名作者类别本数 da.Fill(dt); dataGridView1.DataSource = dt; con.Close();图书更新代码SqlConnection con1 = new SqlConnection(Initial Catalog=lk
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1