求C#连接数据库完整代码
求C#连接数据库完整代码
2011-10-26 20:22
2011-10-26 20:46
2011-10-26 20:47
程序代码:private int SetHasEst()
{
string conString;
SqlConnection sqlcon = new SqlConnection(@"Server = PC--20110803JXD\SQLEXPRESS;Database = Mltmd;User ID=sa;Password='wfl137632'");
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlcon;
int i = 1; //1连接数据库成功,0失败
try
{
sqlcon.Open();
this.con.Open();
conString = "SELECT * FROM Picture WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
= conString;
this.picHasEst = this.getExsRows(cmd);
conString = "SELECT * FROM Document WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
= conString;
this.docHasEst = this.getExsRows(cmd);
conString = "SELECT * FROM Record WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
= conString;
this.audHasEst = this.getExsRows(cmd);
conString = "SELECT * FROM Video WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
= conString;
this.vidHasEst = this.getExsRows(cmd);
conString = "SELECT * FROM Chart WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
= conString;
this.chtHasEst = this.getExsRows(cmd);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
i = 0;
}
finally
{
sqlcon.Close();
}
return i;
}

2011-10-26 22:52
程序代码:private void loadProvince()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = this.con; //private SqlConnection con=new SqlConnection(@"Server = PC--20110803JXD\SQLEXPRESS;Database = Dsdv;User ID=sa;Password='wfl137632'");
= "SELECT dsdvsn,dsdvcd FROM dsdv WHERE dsdvcd LIKE '__0000000000000'";
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
this.cbProvince.Items.Add(dr[0]);
this.pvcdlist.Add(dr[1]);
}
dr.Close();
}

2011-10-26 22:54
2011-10-27 16:27
2011-10-27 17:47