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 ");
}
}
}

Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 1:02 AM EDT
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 +")";
Manj N144 reputationPosted Jul 31, 2013, 1:11 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 1:17 AM EDT
Try like this
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 1:22 AM EDT
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
Manj N144 reputationPosted Jul 31, 2013, 1:30 AM EDT
SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
as
Object reference not set to an instance of an object.
NullReferenceException was unhandled by user..
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 1:34 AM EDT
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
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 1:35 AM EDT
providerName="System.Data.SqlClient" />
using (SqlConnection MyConnection = new SqlConnection(ConfigurationManager.ConnectionString["conString"].ToString()))
{
Regards,
Iftikar
Manj N144 reputationPosted Jul 31, 2013, 1:56 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 2:00 AM EDT
Regards,
Iftikar
Manj N144 reputationPosted Jul 31, 2013, 2:17 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 2:22 AM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 2:34 AM EDT
Manj N144 reputationPosted Jul 31, 2013, 2:34 AM EDT
SqlConnection MyConnection = new SqlConnection(ConfigurationManager.connectionString["conString"].ToString());
what is d error in this line?
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 2:37 AM EDT
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);
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 2:39 AM EDT
string strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
Regards,
Iftikar
Manj N144 reputationPosted Jul 31, 2013, 2:46 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 2:50 AM EDT
string strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
Regards,
Iftikar
Manj N144 reputationPosted Jul 31, 2013, 3:02 AM EDT
error.. thse are not containing in content
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 3:05 AM EDT
Regards,
Iftikar