コードに問題はありませんか?? 動作せず、例外オブジェクト ref をスローしています。オブジェクトのインスタンスに設定されていません。例外は datageneric.cs ファイルのコードラインstring DbConnectionString = Connection.ConnectionString;にあります。
接続.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
public static class Connection
{
private static string constr = "server=.;database=foood;";
public static string ConnectionString
{
get
{
return constr;
}
set
{
constr = value;
}
}
public static string ProviderName { get; set; }
static Connection()
{
ConnectionString =WebConfigurationManager.ConnectionStrings["constring"].ConnectionString;
ProviderName = WebConfigurationManager.ConnectionStrings["constring"].ProviderName;
}
}
DataGeneric.cs
public static DbCommand CreateCommand()
{
DbCommand cmd=null;
try
{
string DbConnectionString = Connection.ConnectionString;
string DbProviderName = Connection.ProviderName;
DbProviderFactory factory = DbProviderFactories.GetFactory(DbProviderName);
DbConnection conn = factory.CreateConnection();
conn.ConnectionString = DbConnectionString;
cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
}
catch (Exception ex) { }
return cmd;
}
GetData.cs
public static DataTable gimmedata()
{
string Query = "select * from [slider]";
DbCommand cmd = DataGeneric.CreateCommand();
cmd.CommandText = Query;
DataTable dt = DataGeneric.ExecuteSelectCommand(cmd);
return dt;
}
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = GetData.gimmedata();
GridView1.DataSource = dt;
GridView1.DataBind();
}