Hi,
I tried to Retrieving Data from SQL by using the below code. But i am getting the following error Invalid attempt to read when no data is present. Try to help resolve my problem.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace wenservdemo
{
public partial class Testpage1 : System.Web.UI.Page
{
protected void Read_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connection string);
string str;
SqlCommand com;
con.Open();
str = "select * from tsttable1 where FName='" + FName.Text + "'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
reader.Read();
FName.Text = reader["FName"].ToString();
reader.Read();
LName.Text = reader["LName"].ToString();
reader.Read();
Company.Text = reader["Company"].ToString();
reader.Read();
Position.Text = reader["Position"].ToString();
reader.Close();
con.Close();
}
}
}


Ravi PatelRank #439 · 5.7K reputationPosted Mar 30, 2016, 12:41 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Mar 30, 2016, 1:38 AM EDT
Pramod ThakurRank #400 · 6.3K reputationPosted Mar 30, 2016, 1:49 AM EDT
Satheesh PalaniRank #4,713 · 329 reputationPosted Mar 30, 2016, 2:07 AM EDT
Satheesh PalaniRank #4,713 · 329 reputationPosted Mar 30, 2016, 2:09 AM EDT
Satheesh PalaniRank #4,713 · 329 reputationPosted Mar 30, 2016, 2:09 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Mar 30, 2016, 2:46 AM EDT