Last post Jun 02, 2013 10:53 PM by Jamobor yao - MSFT
None
0 Points
3 Posts
May 30, 2013 05:44 AM|akshitbansal|LINK
I have designed a page using inline programming that is using strbuild.append.
I have declared strings which i want to be fetched from the database.
Eg. String address ="";
strbuild.append("address is"+address);
i want address from the database.
Please tell me about it including establishing the connection as well
Contributor
3315 Points
403 Posts
Microsoft
May 31, 2013 01:24 AM|Jamobor yao - MSFT|LINK
hi,
you need to connect with sql,then get the variables you want.
take a look at the following link.
http://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C
Hope it can help you
May 31, 2013 01:46 AM|akshitbansal|LINK
Thank you , it helped me a lot.
But can you give me an example based on the what i mentioned in my thread.
If i select address from database then how can i bind it to the address string.
This will clear my query.
Jun 02, 2013 10:53 PM|Jamobor yao - MSFT|LINK
you can try such as the following code
SqlConnection conn = new SqlConnection(GetConnectionString()); conn.Open(); string qury = "select Emp_id,Password from loginuser where (name=@Emp_id) and (Password=@Password)"; SqlCommand cmd = new SqlCommand(qury, conn); cmd.Parameters.AddWithValue("@Emp_id", name); cmd.Parameters.AddWithValue("@Password", password); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count >= 0) { string address = dt.Rows[0]["address"].ToString(); }
you may attention following points.
1).GetConnectionString() that return your database connection;
2).qury is your sqlcommand and you can user yours.
Hope it will help you
None
0 Points
3 Posts
How can i bind variables to database in sql server?
May 30, 2013 05:44 AM|akshitbansal|LINK
I have designed a page using inline programming that is using strbuild.append.
I have declared strings which i want to be fetched from the database.
Eg. String address ="";
strbuild.append("address is"+address);
i want address from the database.
Please tell me about it including establishing the connection as well
Contributor
3315 Points
403 Posts
Microsoft
Re: How can i bind variables to database in sql server?
May 31, 2013 01:24 AM|Jamobor yao - MSFT|LINK
hi,
you need to connect with sql,then get the variables you want.
take a look at the following link.
http://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C
Hope it can help you
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
None
0 Points
3 Posts
Re: How can i bind variables to database in sql server?
May 31, 2013 01:46 AM|akshitbansal|LINK
Thank you , it helped me a lot.
But can you give me an example based on the what i mentioned in my thread.
If i select address from database then how can i bind it to the address string.
This will clear my query.
Contributor
3315 Points
403 Posts
Microsoft
Re: How can i bind variables to database in sql server?
Jun 02, 2013 10:53 PM|Jamobor yao - MSFT|LINK
hi,
you can try such as the following code
you may attention following points.
1).GetConnectionString() that return your database connection;
2).qury is your sqlcommand and you can user yours.
Hope it will help you
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.