error in insert,update delete

Posted by Sachin19 under ASP.NET on 11/30/2010 | Points: 10 | Views : 1080 | Status : [Member] | Replies : 7
I HAVE A PEOBLEM WHEN RUNNING THE FOLLOWING APPLICATION:



I AM GETTING FOLLOWING ERROR ON THIS CODE:
private string GetConnectionString()

{

return System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;

}


nullRefrenceExeception was unhandled by user code
PLZ TEEL ME WHAT WILL I DO ON THIS SITUATION
POST ME ON MY ID: sachingup19@gmail.com




Responses

Posted by: Raja on: 11/30/2010 [Member] Starter | Points: 25

Up
0
Down
Its strange that you have provided your email id and have instructed to post the answer in your email.

You want the solution free, you want the solution quick and on top of that you want the solution to be posted in your email means without doing anything you want someone to provide the solution to you. In this way, its hard to learn things.

Anyways the problem could be in your case is that "DBConnection " is not defined in connectionStrings setting of your web.config file. Add below code snippet in your web.config file.

<connectionStrings>

<add name="DBConnection" connectionString="your connection string"/>
</connectionStrings>


Hope this will solve your problem!

Regards,
Raja, USA

Sachin19, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sachin19 on: 11/30/2010 [Member] Starter | Points: 25

Up
0
Down
how can i make tree view presentation?
tell me the example of tree view

Sachin19, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 12/1/2010 [Member] Starter | Points: 25

Up
0
Down
Search this website, a lot of examples are there related with tree view. Read this tutorials http://www.dotnetfunda.com/tutorials/controls/treeview.aspx

Thanks

Regards,
Raja, USA

Sachin19, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gokul on: 12/1/2010 [Member] Starter | Points: 25

Up
0
Down
Use this code and try:
In .aspx page:
SqlConnection con= new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
con.open();
sqlcommand cmd= new sqlcommand();
string query;
query="Your query";
cmd= new sqlcommand(query,con);
cmd.executeNonQuery();
con.close();

In web config file:

<appSettings>
<add key="ConnectionString" value="Data Source=Server Name;Initial Catalog=DB Name;Integrated Security=True"/>
</appSettings>
<connectionStrings>
<add name=" Your Unique NAme" connectionString="Data Source=Server Name;Initial Cataolg=DB Name"/>
</connectionStrings>



Thanks and Regards,
GokulNath Nithy.

Sachin19, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gokul on: 12/1/2010 [Member] Starter | Points: 25

Up
0
Down
Check your Db columns creation. You would ve set a column property to null and the value that u gave will not be accepted. Try it.

Thanks and Regards,
GokulNath Nithy.

Sachin19, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 1/22/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi, Sachin19

firstly u add ur connection string DBConnection in to web config file

Thanks
Prabhakar

Best Regard's
Prabhakar

Sachin19, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/22/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

The problem is in the webconfig you have failed to give your db connection string DBConnection element.

Give connection string in web.config like this

<appSettings>
<add key="ConnectionString"
value="server=localhost;database=Northwind;uid=sa;password=secret;" />
</appSettings>


Thanks
Karthik
www.f5Debug.net

Sachin19, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response