SQL Server 学习心得_sqlserver学习心得

2020-02-28 学习培训心得体会 下载本文

SQL Server 学习心得由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“sqlserver学习心得”。

SQL Server 2005学习心得(已变成DLL控件可直接调用)

1、C#编程连接SQL Server 2005 数据库的代码:

答: SqlConnection myconnection = new SqlConnection(“Integrated Security=SSPI;Initial Catalog=' 数据库名 ';Data Source='服务器名';User ID='用户登录名';Paword='密码';Connect Timeout=30”);

myconnection.Open();//打开数据库

obj SqlConnection.Close();//关闭数据库

2、C#编程访问数据表中的数据:

答:string SQL = “select EmpName From tb_EmpInfo”;

SqlCommand thisCommand = new SqlCommand(SQL,myconnection);

SqlDataReader thisReader = thisCommand.ExecuteReader();

while(thisReader.Read())//读取数据关键代码

{

MeageBox.Show(thisReader[“EmpName”].ToString());//输出数据

}

3、C#编程访问查询数据表的数据

答 string SQL = “select EmpName From tb_EmpInfo where EmpName=‘邵珠勇’”;

SqlCommand thisCommand = new SqlCommand(SQL,myconnection);

SqlDataReader thisReader = thisCommand.ExecuteReader();

while(thisReader.Read())//读取数据关键代码

{

MeageBox.Show(thisReader[“EmpName”].ToString());//输出数据

}

4、C#编程访问并往数据表中插入数据

string SQL = “insert into

tb_EmpInfo(EmpId,EmpName,EmpLoginName,EmpLoginPwd,EmpSex,EmpBirthDay,EmpDept,EmpPost,EmpPhone,EmpPhoneM,EmpAddre,EmpFalg)values('12345678','束同同','zhanghan','123','男','1990/02/21','食品部','组长','1234567','***','安徽省',0)”;

SqlCommand thisCommand = new SqlCommand(SQL, myconnection);

thisCommand.ExecuteNonQuery();

5、C#编程访问并更新数据表中的数据内容

答:string SQL = “update tb_EmpInfo set EmpName= '束同',EmpSex='女'” + “ where EmpID='12345678'”;SqlCommand thisCommand = new SqlCommand(SQL, myconnection);

thisCommand.ExecuteNonQuery();

6、C#编程访问并删除数据表中的数据内容

答: string SQL = “delete from tb_EmpInfo where EmpID='12345678'”;

SqlCommand thisCommand = new SqlCommand(SQL, myconnection);

thisCommand.ExecuteNonQuery();

7、C#中查询代码

答:string SQL = “select EmpName From tb_EmpInfo”;DataSet ds = new DataSet();

SqlDataAdapter obj=new SqlDataAdapter();

obj.SelectCommand = new SqlCommand(SQL,myconnection);obj.Fill(ds, “tb_EmpInfo”);

dataGridView1.DataSource = ds.Tables[0];

《SQL Server 学习心得.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
SQL Server 学习心得
点击下载文档
相关专题 sqlserver学习心得 学习心得 sql Server sqlserver学习心得 学习心得 sql Server
[学习培训心得体会]相关推荐
    [学习培训心得体会]热门文章
      下载全文