Hi All,
Actually i want to dispaly the results of a select statement in a TextBox. Pls anyone give me an idea how to do it.
Thanks
Hi All,
Actually i want to dispaly the results of a select statement in a TextBox. Pls anyone give me an idea how to do it.
Thanks
MyTextBox.Text="result of select";
will show result of select in your textbox.
Otherwise use the (DataBindings) property
private void button1_Click(object sender, EventArgs e)
{
const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
const string query = "Select * From Invoice Where InvNumber = @InvNumber";
using (DataTable dt = new DataTable())
{
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.Add(new SqlParameter("@InvNumber", 1100));
using (SqlDataReader dr = cmd.ExecuteReader())
{
dt.Load(dr);
}
}
conn.Close();
}
if (dt.Rows.Count != 1)
throw new Exception("Record not found!");
DataRow row = dt.Rows[0];
int invNumber = Convert.ToInt32(row["InvNumber"]);
string invStatus = Convert.ToString(row["InvStatus"]);
//Bind the text boxes after you have the values
System.Diagnostics.Debugger.Break();
}
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.