C# 创建窗口程序两个重要文件
作者:互联网
SqlManage.cs
1 class SqlManage 2 { 3 public static string cnnstring = "Server=wit;Database=test2009;Uid=sa;Pwd=123456;"; 4 public static SqlConnection cnn = null; 5 6 public static DataTable TableSelect(string sql) 7 { 8 try 9 { 10 DataTable table= new DataTable(); 11 SqlDataAdapter sdp = new SqlDataAdapter(sql,SqlManage.cnnstring); 12 sdp.Fill(table); 13 return table; 14 } 15 catch (Exception ex) 16 { 17 MessageBox.Show(ex.Message); 18 return null; 19 } 20 } 21 22 public static void TableChange(string sql) 23 { 24 try 25 { 26 SqlCommand cmd = new SqlCommand(sql,SqlManage.cnn); 27 if (cmd.ExecuteNonQuery() > 0) 28 { 29 MessageBox.Show("操作成功!"); 30 } 31 else 32 { 33 MessageBox.Show("操作失败!\n检查数据库是否有该记录"); 34 } 35 } 36 catch (Exception ex) 37 { 38 MessageBox.Show(ex.Message); 39 } 40 } 41 42 public static void SetDataGridView(DataGridView d) 43 { 44 d.ReadOnly = true; 45 d.AllowUserToAddRows = false; 46 d.RowHeadersVisible = false; 47 d.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 48 } 49 50 public static bool JudTextBox(TextBox t) 51 { 52 if (t.Text.Trim().Length < 1) 53 { 54 return false; 55 } 56 else 57 { 58 return true; 59 } 60 } 61 }
Program.cs
1 static void Main() 2 { 3 Application.EnableVisualStyles(); 4 Application.SetCompatibleTextRenderingDefault(false); 5 6 try 7 { 8 SqlManage.cnn = new SqlConnection(SqlManage.cnnstring); 9 SqlManage.cnn.Open(); 10 } 11 catch (Exception ex) 12 { 13 MessageBox.Show(ex.Message); 14 return; 15 } 16 Application.Run(new FormMain()); 17 18 SqlManage.cnn.Close(); 19 }
标签:窗口,Show,C#,重要文件,static,ex,SqlManage,return,public 来源: https://www.cnblogs.com/lixiaov/p/10552464.html