Tech
Forums
Jobs
Books
Events
Live
Learn
More
Training
Interviews
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Connectionstring and Sqlreader
Help Needed
Jan 26 2014 8:17 AM
942
Reply
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;
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
Please Provide me the Application to Dot Matrix Print
SQL Query - Schedular in C#.net Plzz Help..