using (OleDbConnection conn = new OleDbConnection(settings.ConnectionString))
System.NullReferenceException:未将对象引用设置到对象的实例,怎么解决啊?很急!...
System.NullReferenceException: 未将对象引用设置到对象的实例,怎么解决啊?很急!
展开
1个回答
展开全部
看看能有点用吗
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace DAL
{
public class DBHelper
{
private string connectionString= @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = "
+ Application.StartupPath + @"\Data\NMS.mdb";
/// <summary>
/// 执行增删改操作 返回int 类型
/// </summary>
/// <param name="sql"></param>
/// <param name="para"></param>
/// <returns></returns>
public static int GetScalar(string sql)
{
int result = 0;
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
result = cmd.ExecuteNonQuery();
conn.Dispose();
conn.Close();
}
return result;
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace DAL
{
public class DBHelper
{
private string connectionString= @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = "
+ Application.StartupPath + @"\Data\NMS.mdb";
/// <summary>
/// 执行增删改操作 返回int 类型
/// </summary>
/// <param name="sql"></param>
/// <param name="para"></param>
/// <returns></returns>
public static int GetScalar(string sql)
{
int result = 0;
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
result = cmd.ExecuteNonQuery();
conn.Dispose();
conn.Close();
}
return result;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询