怎么在c#中利用checkedListBox1控件连接数据库

  介绍

这篇文章给大家介绍怎么在c#中利用checkedListBox1控件连接数据库,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

using 系统;   using  System.Collections;   using  System.Collections.Generic;   using  System.Data;   using  System.Diagnostics;   using  System.Data.Sql;   using  System.Data.SqlClient;   namespace  WindowsFormsApplication1   {   class  DataDase才能   {才能   ,,,public  string  Con =,““   ,,,public  DataTable  DATA_SQL (string  SQL)   ,,,{   ,,,,,SqlConnection  myconn =, new  SqlConnection (Con);   ,,,,,//反对为数据库连接字段   ,,,,,SqlDataAdapter  myadapter =, new  SqlDataAdapter (SQL, myconn);   ,,,,,DataSet  mydataset =, new 数据集();   ,,,,,myadapter.Fill (mydataset);   ,,,,,return  mydataset.Tables [0];   ,,,}   ,,,public  void  RUN_SQL (string  SQL)   ,,,{   ,,,,,SqlConnection  myconn =, new  SqlConnection (Con);   ,,,,,SqlDataAdapter  myadapter =, new  SqlDataAdapter (SQL, myconn);   ,,,,,DataSet  mydataset =, new 数据集();   ,,,,,myadapter.Fill (mydataset);   ,,,}   ,,}   } using 系统;   using  System.Collections.Generic;   using  System.ComponentModel;   using  System.Data;   using  System.Drawing;   using 来;   using 包含;   using  System.Windows.Forms;   using 先;   namespace  WindowsFormsApplication1   {   public 才能;partial  class  Form1 :形式   {才能   ,,,public  Form1 ()   ,,,{   ,,,,,InitializeComponent ();   ,,,}   ,,,private  void  Form1_Load (object ,发送方,EventArgs  e)   ,,,{   ,,,}   ,,,private  void  button1_Click (object ,发送方,EventArgs  e)   ,,,{   ,,,,,checkedListBox1.Items.Clear ();   ,,,,,DataDase  database =, new  DataDase ();   ,,,,,database.Con =, @" Data  Source =, 192.168.1.3;, Initial  Catalog =, zxl;, User  Id =, sa;, Password =, zxl;,“;   ,,,,,DataTable  dt, t;   ,,,,,t =, database.DATA_SQL (“select  *,得到学生信息表,where  c#=& # 39;“, +, textBox1.Text  +,“& # 39;“);   ,,,,,textBox2.Text=, t.Rows [0] [1] .ToString ();   ,,,,,if  (t.Rows [0] [3] .ToString () .Equals (“1“))   ,,,,,{   ,,,,,,,radioButton1.Checked=true;   ,,,,,}   ,,,,,else  {   ,,,,,,,radioButton2.Checked =,真的;   ,,,,,}   ,,,,,dt =, database.DATA_SQL (“SELECT 爱好表.love 得到学生信息表,INNER  JOIN 学生爱好表,提醒学生信息表c #,=,学生爱好表c #, INNER  JOIN 爱好表,提醒学生爱好表。s #,=,爱好表。s #, WHERE (学生信息表c #,=, & # 39;“+ textBox1.Text +“& # 39;)“);   ,,,,,for  (int 小姐:=,0;,小姐:& lt;, dt.Rows.Count;,我+ +)   ,,,,,{   ,,,,,,,checkedListBox1.Items.Add (dt.Rows[我][0]);   ,,,,,}   ,,,}   ,,}   } create  database  zxl   use  zxl   ----------------------------------------------   create  table 学生信息表(   c#, char (5), primary 键,   num  char (11), not 空,   name  char (6), not 空,   int sex    )   create  table 爱好表(   年代#,char (5), primary 键,   love  char (4), not  null   )   create  table 学生爱好表(   年代#,char (5), references 爱好表(#),   c#, char (5), references 学生信息表(c#),   code  char (10), not 空,   primary 关键(c s #, #)   )   ----------------------------------------------   insert  into 学生信息表,值(& # 39;1 & # 39;& # 39;111111 & # 39;,& # 39;张# 39;(1)   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在c#中利用checkedListBox1控件连接数据库