向書(shū)本學(xué)習(xí),還要向?qū)嵺`學(xué)習(xí)、向生活學(xué)習(xí)。消化已有知識(shí),
而且要力求有所發(fā)現(xiàn)、有所發(fā)明、有所創(chuàng)造
2019/3/24 8:18:11
連接數(shù)據(jù)庫(kù)
源代碼:
private void Page_Load(object sender, System.EventArgs e)
{
myConnection = new SqlConnection("server=localhost;" +
"database=zhishi;uid=scm;pwd=scm");
//if (!IsPostBack) BindGrid();
}
查詢數(shù)據(jù)庫(kù)
源代碼:
public void BindGrid()
{
myConnection = new SqlConnection("server=localhost;" +
"database=zhishi;uid=scm;pwd=scm");
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT top 10 * FROM" +
" wujml", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds);
MyDataGrid.DataSource=ds;
MyDataGrid.DataBind();
}
增刪改數(shù)據(jù)庫(kù)
源代碼:
public void AddAuthor_Click()
{
String insertCmd = "insert into wujml(wujid,wujbt,wujlj1) "+
"values ('99999','111','3131')";
SqlCommand myCommand = new SqlCommand(insertCmd, myConnection);
myCommand.Connection.Open();
try
{
myCommand.ExecuteNonQuery();
//Message.InnerHtml = "Record Added
" + insertCmd;
}
catch
{
//Console.WriteLine("{0} Second exception caught.", e);
this.body.Text = "*************";
}
myCommand.Connection.Close();
}
連接SQL Server數(shù)據(jù)庫(kù)
源代碼:
//作用: 連接SQL Server數(shù)據(jù)庫(kù)
//參數(shù):ServerName 服務(wù)器名,DBName 數(shù)據(jù)庫(kù)名,UserID 用戶名,UserPwd 用戶密碼
public void ConnSQLServer(string ServerName, string DBName)
{
mCnnDB.ConnectionString = "uid=;pwd= ;driver={SQL Server};" +
"server=" +ServerName+
";database=" + DBName;
mCnnDB.Open(mCnnDB.ConnectionString,"sa","",-1);
}
public void ConnSQLServer(string ServerName, string DBName,string UserID,string UserPwd)
{ mCnnDB.ConnectionString = "uid='" + UserID + "';pwd='" + UserPwd + "' ;driver={SQL Server};" +
"server=" + ServerName +
";database=" + DBName;
mCnnDB.Open(mCnnDB.ConnectionString,UserID,UserPwd,-1);;
}
連接ODBC數(shù)據(jù)庫(kù)
源代碼:
// '作用: 連接ODBC數(shù)據(jù)庫(kù)
// '參數(shù):dsnName ODBC名,UserID 用戶名,UserPwd 用戶密碼
public void ConnODBC(string dsnName )
{
mCnnDB.Provider = "MSDASQL";
mCnnDB.ConnectionString = "Data Source='" + dsnName + "'";
mCnnDB.Open(mCnnDB.ConnectionString,"","",-1);
}
public void ConnODBC(string dsnName,string UserID, string UserPwd )
{ mCnnDB.Provider = "MSDASQL";
mCnnDB.ConnectionString = "User ID='" +UserID + "';" +
"Password='" + UserPwd + "';" +
"Data Source='"+dsnName+ "'";
mCnnDB.Open(mCnnDB.ConnectionString,UserID,UserPwd,-1 );
}
深圳市南山區(qū)南山街道南海大道西桂廟路北陽(yáng)光華藝大廈1棟4F、4G-04
咨詢電話:136 8237 6272
大客戶咨詢:139 0290 5075
業(yè)務(wù)QQ:195006118
技術(shù)QQ:179981967
深圳精銳軟件 深圳APP開(kāi)發(fā) 深圳小程序開(kāi)發(fā) 深圳微信開(kāi)發(fā) 深圳APP制作 深圳營(yíng)銷(xiāo)推廣 深圳網(wǎng)站建設(shè) 深圳游戲開(kāi)發(fā)
客戶案列
新聞資訊
資質(zhì)榮譽(yù)
團(tuán)隊(duì)風(fēng)采
項(xiàng)目進(jìn)度查詢
售前QQ咨詢
QQ溝通 項(xiàng)目QQ溝通