再探C#——控件調用/數據庫操作/配置文件
阿新 • • 發佈:2018-03-17
HR 利用 查詢 .text click cut initial comm man
因為這學期的設計模式課需要進行面向對象的編程, 所以這裏抽時間復習一下C#
命名空間的設計目的是提供一種讓一組名稱與其他名稱分隔開的方式。
利用對象指針調用控件:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MyClass.method1(textBox1); } } publicclass MyClass { static public void method1(System.Windows.Forms.TextBox t1) { t1.Text = "6666666666666666"; } }
數據庫:
using System.Data;
using System.Data.SqlClient;
連接數據庫:
string constr = "server=.;database=數據庫名;integrated security=SSPI";
SqlConnection con = new SqlConnection();
con.ConnectionString = constr;
con.Open();
執行命令:
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "查詢語句";
SqlDataReader dr = com.ExecuteReader();
再探C#——控件調用/數據庫操作/配置文件