错误 :无法使用实例引用来访问成员“HRMan.DataAccess.conn”;请改用类型名来限定它 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms; namespace HRMan
{
class DataAccess
{
static SqlConnection conn;
static string Str = "Data Source=(local);Initial Catalog =HRMan;Integrated Security = SSPI;";
public DataAccess()
{
conn = new SqlConnection(Str);
conn.Open();
}
public int ExeSQL(string sql)
{
//实例化一个Sqlcommand对象,参数为sql语句和数据库连接成员
SqlCommand cmd = new SqlCommand(sql, this.conn);
try
{
//调用sqlcommand对象的executenonquery()访问
cmd.ExecuteNonQuery();
return 0;
}
catch (System.Data.SqlClient.SqlException ex) //异常处理
{
MessageBox.Show(ex.Message.ToString());
return -1;
}
finally
{
cmd.Dispose();
this.conn.Close();
}
} } } |