You need to look at your code: the trace is pretty explicit - look at the CSharp.aspx.cs file, at line 17.
Somewhere, on that line of code you are either trying to use a null value as a class instance (as in myClassVaraible.MyProperty with myClassVariable not set to a new value), or you are passing a null value into a method that doesn't expect one.
Further information we can't give!
this is my CSharp.aspx.cs file
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings[@"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=KACHU-PC\SQLEXPRESS"].ConnectionString;
string strQuery = "select ID, Name from tblFiles order by ID";
SqlCommand cmd = new SqlCommand(strQuery);
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
GridView2.DataSource = dt;
GridView2.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
sda.Dispose();
con.Dispose();
dt.Dispose();
}
}
}
n on line 17 its connection string and connection string is rite as far i re re checked..
OK...that's not too difficult.
When you use System.Configuration.ConfigurationManager.ConnectionStrings you are supposed to use the name of a connection string in your web.config:
<connectionStrings>
<add name="LoggingDatabase" connectionString="Database=SMLogging;Data Source=GRIFFPC\SQLEXPRESS;Initial Catalog=SMLogging;Integrated Security=True"/>
<add name="MembershipDatabase" connectionString="Database=SMMembership;Data Source=GRIFFPC\SQLEXPRESS;Initial Catalog=SMMembership;Integrated Security=True"/>
<add name="DownloadDatabase" connectionString="Data Source=GRIFFPC\SQLEXPRESS;Initial Catalog=SMInterchange;Integrated Security=True"/>
</connectionStrings>
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["MembershipDatabase"].ConnectionString;
You are trying to access a connection string called "
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=KACHU-PC\SQLEXPRESS
" which doesn't exist. So it throws an null reference error when you access it.
Either use the name of a web.config string or use the actual string directly and it will work. The former is preferable, as it means you can make changes without altering the code.