3 回答

TA貢獻1851條經(jīng)驗 獲得超5個贊
PC-20090625HIOS\SQLEXPRESS 中包含一個轉(zhuǎn)義字符"\",他會把之后的一個字符組合起來做轉(zhuǎn)義:\S
你用兩個斜杠試試.
PC-20090625HIOS\\SQLEXPRESS

TA貢獻1847條經(jīng)驗 獲得超7個贊
定義一個類,寫數(shù)據(jù)庫連接,執(zhí)行語句,讀取等方法,然后在要用的類里實例化一下,在調(diào)用就可以了,我用的是C#,你看看
class dosql
{
public OleDbConnection getcon()
{
string M_str_oledbcon = "連接字符串";
OleDbConnection myCon = new OleDbConnection(M_str_oledbcon);
return myCon;
}
public void getcom(string M_str_oledbstr)
{
OleDbConnection oledbcon = this.getcon();
oledbcon.Open();
OleDbCommand oledbcom = new OleDbCommand(M_str_oledbstr, oledbcon);
oledbcom.ExecuteNonQuery();
oledbcom.Dispose();
oledbcon.Close();
oledbcon.Dispose();
}
public DataSet getds(string M_str_oledbcstr, string M_str_table)
{
OleDbConnection oledbcon = this.getcon();
OleDbDataAdapter oledbda = new OleDbDataAdapter(M_str_oledbcstr, oledbcon);
DataSet myds = new DataSet();
oledbda.Fill(myds, M_str_table);
return myds;
}
public OleDbDataReader getread(string M_str_oledbstr)
{
OleDbConnection oledbcon = this.getcon();
OleDbCommand oledbcom = new OleDbCommand(M_str_oledbstr, oledbcon);
oledbcon.Open();
OleDbDataReader oledbread = oledbcom.ExecuteReader(CommandBehavior.CloseConnection);
return oledbread;
}
}
你對照VB的函數(shù)修改下

TA貢獻1842條經(jīng)驗 獲得超13個贊
string strConnection = " Data Source=PC-20090625HIOS\SQLEXPRESS;Initial Catalog=student;Integrated Security=True"; 改為string strConnection = " Data Source=PC-20090625HIOS\\SQLEXPRESS;Initial Catalog=student;Integrated Security=True"; 或者string strConnection =@ " Data Source=PC-20090625HIOS\SQLEXPRESS;Initial Catalog=student;Integrated Security=True"; 試試看,不行的話你就用用戶加密碼的別用windows驗證
- 3 回答
- 0 關(guān)注
- 283 瀏覽