1..链接SQL
1.1 链接字符串
WINDOWS集成验证方式:
server=localhost;(ID地址或者主机名) initial cataloh = pubs;(数据库名称); integrated security=ture;(建立安全的链接)
SQL 验证方式
server=localhost;(ID地址或者主机名) initial cataloh = pubs;(数据库名称) user id= ; password=;
1.2建立链接
using system.data.sqlclient; //导入SQLCLIENT命名空间
string constr= data source=(local); initial catalog=; integrated security="true"
sqlconnection conn=new sqlconnection(conste); //建立链接对象
EG. 数据库更新操作
string str = "Data Source=.;Initial Catalog=yao;User ID=sa;Password=123";
SqlConnection con = new SqlConnection(str);
string strSql = "update yonghu set username=‘" + gainame.Text + "‘,password=‘" + gaipass.Text + "‘,sex=‘" + gaisex.Text + "‘,youxiang=‘" + gaiyouxiang.Text + "‘ , dianhua=‘" + gaiphone.Text + "‘ where username=‘" + xiugainame.Text + "‘";
SqlCommand cmd = new SqlCommand(strSql, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
熟悉数据库操作。实现数据库调取图片路径。