TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bhavesh R
NA
15
3.7k
Am getting error while connecting by db with visual studio 2019
May 1 2021 7:46 AM
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
namespace aspsnippets.Models
{
public class DBconnection
{
public List<asppiechart> DBconnect()
{
List<asppiechart> chartData = new List<asppiechart>();
string connectionString = ConfigurationManager.ConnectionStrings["conmydb"].ToString();
SqlConnection sqlConnection = new SqlConnection(connectionString);
string cmd1 = "select * from piechart";
SqlCommand sqlCommand = new SqlCommand(cmd1, sqlConnection);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
while(sqlDataReader.Read())
{
chartData.Add(new asppiechart
{
Month = sqlDataReader["Month"].ToString(),
Values = sqlDataReader["Values"].ToString()
});
}
return chartData;
}
}
}
AM GETTING THIS ERROR:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Configuration.ConnectionStringSettingsCollection.this[string].get returned null.
Reply
Answers (
11
)
Problem in Null object
My lines are not executing where i am setting session in asp.net mvc