hello guys how r u ?
my question is that,
i am creating a web service which is fetching data from database and retrive to client,
my code is below
Web service file
---------------
[WebMethod]
public DataTable DataService()
{
SqlConnection con = new SqlConnection(@"Data Source=HIDAYA2-PC; Integrated Security=True; Database=ProjectTestDB;");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.Connection.Open();
cmd.CommandText = "select * from Person";
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
if (reader.HasRows)
{
dt.Load(reader);
}
cmd.Connection.Close();
return dt;
}
Default.aspx.cs
---------------
protected void Page_Load(object sender, EventArgs e)
{
WebService1.Service service = new WebService1.Service();
GridView1.DataSource = service.DataService();
GridView1.DataBind();
}
my problem is that an exception accured over there
reply soon
thanks.
Loading
knightsPosted Aug 16, 2011, 10:19 PM
Jonathas SucupiraPosted Aug 16, 2011, 9:06 AM
Faisal AnsariPosted Aug 16, 2011, 4:14 AM
Jonathas SucupiraPosted Aug 15, 2011, 10:58 AM
var con = new SqlConnection(@"database=ProjectTestDB;server=HIDAYA2-PC;Integrated Security=SSPI;");
var cmd = new SqlCommand { Connection = con, CommandText = "select * from Person" };
var dt = new SqlDataAdapter(cmd);
var datable = new DataTable();
try
{
cmd.Connection.Open();
dt.Fill(datable);
}
catch (Exception)
{
throw;
}
finally
{
if (con.State == ConnectionState.Open)
return datable;
knightsPosted Aug 15, 2011, 10:15 AM