zoaka:
vinz:
DataTable dt = // Set the DataSource here that comes from your Web Service and pass the username as the parameter
For this part i don't understand what to put at the comment part
In your Service create a method that returns a DataTable or a DataSet that accepts the userid as the parameter.. something like:
//A method from your Service
public DataTable GetCustomerInfo(string user)
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE");
try
{
connection.Open();
SqlCommand sqlCmd = new SqlCommand("SELECT * FROM Customers WHERE UserID = @user;", connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlCmd.Parameters.AddWithValue("@user",user);
sqlDa.Fill(dt);
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
return dt;
}
//Then In your ASPX Form
You can reference that method above like below:
private void GetDataFromService(string user)
{
MyWebService service = new MyWebService();
DataTable dt = service.GetCustomerInfo(user); // Set the DataSource here that comes from your Web Service and pass the username as the parameter
if (dt.Rows.Count > 0)
{
TextBox1.Text = dt.Rows[0]["ColumnName1"].ToString(); //Where ColumnName is the Field from the DB that you want to display
TextBox2.Text = dt.Rows[0]["ColumnName2"].ToString();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack){
GetDataFromService(this.User.Identity.Name);
}
}You can refer to the following links below for more info:
http://blogs.interfacett.com/dan-wahlins-blog/2007/3/10/video-creating-web-services-with-the-net-framework.html
http://digitalcolony.com/2007/08/consuming-web-service-in-aspnet.aspx
http://msdn.microsoft.com/en-us/library/ms972326.aspx
zoaka:
vinz:
if (!Page.IsPostBack){
getData(this.User.Identity.Name);
And for this part can explain the this.User.Identity.Name?
It basically get's the current logged user.. Refer to the link provided by Hong Gang for more information.