Error in connecting database using jquery

Posted by Klbaiju under jQuery on 10/22/2012 | Points: 10 | Views : 1192 | Status : [Member] | Replies : 3
Hi,
I want to display some fields from database using jquery

this is the code for connecting database and display
<script type="text/javascript">
$(document).ready(function() {
$('#btnsearch').click(function() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{ CustomerID: '" + $('#txtid').val() + "'}",
url: "Customer.aspx/FetchCustomer",
dataType: "json",
success: function(data) {
var Employee = data.d;
$('#CustomerDetails').append
('<p><strong>' + Employee.Id + "</strong><br />" +
Employee.fname + "<br />" +
Employee.lname+ "<br />" +
"</p>" )
}
});
});
});
</script>
***************************************
.cs code

[WebMethod]
public Employee FetchCustomer(string employeeId)
{
Employee c = new Employee();
SqlConnection con = new SqlConnection("Data Source=BAIJU-PC;Initial Catalog=Baiju;Integrated Security=True");
// SqlDataAdapter da = new SqlDataAdapter("select * from emp wher id='" + employeeId + "'", con);
con.Open();
SqlCommand cmd = new SqlCommand("select * from emp wher id='" + employeeId + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
c.id = dr["id"].ToString();
c.fname = dr["fname"].ToString();
c.lname = dr["LNAME"].ToString();
}

return c;
}
public class Employee
{
public string id { get; set; }
public string fname { get; set; }
public string lname { get; set; }

}

error is when I run the application .cs code is firing
it executes upto this code
SqlDataReader dr = cmd.ExecuteReader();
after this it is not executing.
how to solve this problem

Regards
Baiju




Responses

Posted by: Rickeybglr on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
what error ru getting ??? please post ur error and put ur code into try catch

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Klbaiju on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
error is not executing from
SqlDataReader dr = cmd.ExecuteReader();

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
so ur saying tht ...ur not gettin any error and nothin is displayin rite??
so debug ur code check the value of dr (dataset) is tht empty or it holds value ..

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response