0) My suspicion is that the
datatable
you're binding to goes out of scope when the method exits and becomes null, thus forcing the bound control to display no rows.
1) Calling
sda.Update
is not necessary if you're just retrieving data.
2) I never bind directly to a
DataTable
. Instead use the MVVM pattern to make binding less messy and more convenient.
3) Do the binding in the XAML.
4) Are you sure your sql parameter is really a string, and not an integer? That's highly weird.
5) My method would look something like this:
SqlConnection con = null;
SqlCommand cmd = null;
string text = "1234";
DataTable dt = new DataTable();
try
{
using (con = new SqlConnection("Data Source=\\SQLEXPRESS;Database=CSharpUserLogin; Integrated Security=true"))
{
using (cmd = new SqlCommand("sp_GetUserDetail", con){ CommandType=CommandType.StoredProcedure })
{
cmd.Parameters.Add(new SqlParameter("@userId", text));
SqlDataAdapter sda = new SqlDataAdapter(){ SelectCommand = cmd };
con.Open();
sda.Fill(dt);
}
}
}
catch (Exception ex)
{
}