i am getting error as Object reference not set to an instance of an object.
NullReferenceException was unhandled by user..
public partial class _Default : System.Web.UI.Page
NullReferenceException was unhandled by user..
public partial class _Default : System.Web.UI.Page
{
SqlConnection MyConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
SqlCommand MyCommand= new SqlCommand();
string query;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void submit_Click(object sender, EventArgs e)
{
query="INSERT INTO tablem (name,password) VALUES (" + name +"," + password +")";
try
{
}
catch (NullReferenceException)
{
Console.WriteLine("error ");
}
}
}
Iftikar HussainPosted Jul 31, 2013, 7:05 AM
Regards,
Iftikar
Manj NPosted Jul 31, 2013, 7:02 AM
error.. thse are not containing in content
Iftikar HussainPosted Jul 31, 2013, 6:50 AM
string strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
Regards,
Iftikar
Manj NPosted Jul 31, 2013, 6:46 AM
Iftikar HussainPosted Jul 31, 2013, 6:39 AM
string strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 31, 2013, 6:37 AM
and check it is working or not
string strcon = "Data Source= DatabaseServerName; Integrated Security=true;Initial Catalog= YourDatabaseName; uid=YourUserName; Password=yourpassword; ";
SqlConnection con = new SqlConnection(strcon);
Manj NPosted Jul 31, 2013, 6:34 AM
SqlConnection MyConnection = new SqlConnection(ConfigurationManager.connectionString["conString"].ToString());
what is d error in this line?
Sanjeeb LenkaPosted Jul 31, 2013, 6:34 AM
Iftikar HussainPosted Jul 31, 2013, 6:22 AM
Regards,
Iftikar
Manj NPosted Jul 31, 2013, 6:17 AM
Iftikar HussainPosted Jul 31, 2013, 6:00 AM
Regards,
Iftikar
Manj NPosted Jul 31, 2013, 5:56 AM
Iftikar HussainPosted Jul 31, 2013, 5:35 AM
providerName="System.Data.SqlClient" />
using (SqlConnection MyConnection = new SqlConnection(ConfigurationManager.ConnectionString["conString"].ToString()))
{
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 31, 2013, 5:34 AM
you check your web.config that you declare the connection string or not.
like this
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB" providerName="System.Data.SqlClient"/>
connectionStrings >
just check that
if you got any problem share your web.config code
Manj NPosted Jul 31, 2013, 5:30 AM
SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
as
Object reference not set to an instance of an object.
NullReferenceException was unhandled by user..
Sanjeeb LenkaPosted Jul 31, 2013, 5:22 AM
you did a mistake here
query="INSERT INTO tablem (name,password) VALUES (" + name +"," + password +")";
you miss .Text in this line
after modifing
query="INSERT INTO tablem (name,password) VALUES (" + name.Text +"," + password.Text +")";
use this and check this and reply
Iftikar HussainPosted Jul 31, 2013, 5:17 AM
Try like this
Regards,
Iftikar
Manj NPosted Jul 31, 2013, 5:11 AM
Sanjeeb LenkaPosted Jul 31, 2013, 5:02 AM
From where you are getting name and password for your query. you didn't mention that in code.
query="INSERT INTO tablem (name,password) VALUES (" + name +"," + password +")";