3 回答
TA贡献1851条经验 获得超5个赞
PC-20090625HIOS\SQLEXPRESS 中包含一个转义字符"\",他会把之后的一个字符组合起来做转义:\S
你用两个斜杠试试.
PC-20090625HIOS\\SQLEXPRESS
TA贡献1847条经验 获得超7个赞
定义一个类,写数据库连接,执行语句,读取等方法,然后在要用的类里实例化一下,在调用就可以了,我用的是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的函数修改下
TA贡献1842条经验 获得超12个赞
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 关注
- 246 浏览
添加回答
举报