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
Help Needed
NA
13
23.7k
Connectionstring and Sqlreader
Jan 26 2014 8:17 AM
Hi
I am trying to populate data from table using WCF.My connection string is "ABCD" in App.config file.
when I was debugging the application in "LOCALS" window I see the con value null.Basically it is not able to read the connectionstring. I keep preesing f10 and rdr is giving error "Index out of range exception" .It could be basically since it is not able to read connection string from app.config file.I added reference to configuaration file and also added using system.configuaration. Unless I get the solution I can not learn further. Please give me the solution ASAP.Here is my CODE:
Thanks
public EmployeeWcf GetEmployee(int id)
{
EmployeeWcf employeeWcf = new EmployeeWcf();
string CS = ConfigurationManager.ConnectionStrings["ABCD"].ConnectionString;
using(SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spGetEmployeeWcf",con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramId = new SqlParameter();
paramId.ParameterName = "@Id";
paramId.Value = id;
cmd.Parameters.Add(paramId);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while(rdr.Read())
{
employeeWcf.Id = Convert.ToInt32(rdr["Id"]);
employeeWcf.Name = rdr["Name"].ToString();
employeeWcf.Gender = rdr["Gender"].ToString();
employeeWcf.DateOfBirth = Convert.ToDateTime(rdr["DateOfBirth"]);
}
return employeeWcf;
Reply
Answers (
2
)
where can I find it PLEASE!
SQL Query - Schedular in C#.net Plzz Help..