Is there any way that I can retrieve any data from the database in the SQL server without using the DataGrid viewer or alike?
I want to retrieve a data that would go straightly to the textbox but not in the DataGrid.
Although I'm already used of retrieving files coming from the datagrid to the the textbox, can i just retrieve it directly from the database itself?
any ideas?

Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Apr 3, 2008, 4:14 AM EDT
It is very simple.Just read the data from table using data reader and and assign the data in textbox. I have given the code below.
if (sdrData.HasRows)
{
if (sdrData.Read())
{
txtCustomerID.Text = sdrData["cus_vch_Id"].ToString();
txtCustomerName.Text = sdrData["cus_vch_CustomerName"].ToString();
txtAddress.Text = sdrData["cus_vch_Address"].ToString();
txtCity.Text = sdrData["cus_vch_City"].ToString();
txtState.Text = sdrData["cus_vch_State"].ToString();
txtZip.Text = sdrData["cus_int_Zip"].ToString();
txtTelephone.Text = sdrData["cus_vch_Telephone"].ToString();
txtFax.Text = sdrData["cus_vch_Fax"].ToString();
txtEmail.Text = sdrData["cus_vch_Email"].ToString();
txtWebsite.Text = sdrData["cus_vch_WebsiteAddress"].ToString();
txtUserLicences.Text = sdrData["cus_int_MaximumNoLicenses"].ToString();
}
}
Mervha Nifflemhell35 reputationPosted Apr 3, 2008, 3:04 PM EDT
inside the sdr, does
'cus' means the name of the table
'int' means the sql data type
'CustomerName' means the field name
am i getting it right?
Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Apr 7, 2008, 11:06 AM EDT
You could just do the query in the Page_Load as suggested, and populate the TextBox that way.
For example, here is an example using the Northwind sample database:
protected void Page_Load(object sender, EventArgs e) { using (SqlConnection cn = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString)) { SqlCommand cmd = new SqlCommand("SELECT LastName FROM Employees WHERE (EmployeeID = 1)", cn); cn.Open(); TextBox1.Text = cmd.ExecuteScalar().ToString(); } }Bechir BejaouiRank #144 · 15.9K reputationPosted Jun 3, 2008, 3:15 PM EDT
Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Jun 24, 2008, 11:59 AM EDT
Hi,
Thanks for your comments
regard -- Vj