4
Reply

How to get number of rows returned to binding source

Dealy

Dealy

Feb 23 2010 3:14 AM
9.4k
Hello i have the following code based on Northwind database
   public void select_orders(String CustID)
{

string connectionString = @"Server=localConn; Initial Catalog=Northwind; Integrated Security=True";
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("SELECT_ORDERS", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@CustomerID", CustID));
conn.Open();

//Fill The DataTable From Command
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

//Set It To Binding Navigator
BindingSource itmBindSource = new BindingSource();
itmBindSource.DataSource = dt;
itmBindNavigator.BindingSource = itmBindSource;
itmBindNavigator.Dock = DockStyle.Bottom;

TextBox temp_checked = new TextBox();
temp_checked.DataBindings.Add("Text", itmBindSource, "ShipPostalCode");
if (temp_checked.Text != null)
checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
else
checkBox1.CheckState = System.Windows.Forms.CheckState.Unchecked;

custID_txt.DataBindings.Add("Text", itmBindSource, "CustomerID");
shipRegion_combo.DataBindings.Add("SelectedValue", itmBindSource, "ShipRegion");
freight_txt.DataBindings.Add("Text", itmBindSource, "Freight");

orderID_txt.DataBindings.Add("Text", itmBindSource, "OrderID");

}
}

How can i check if it returns any rows? Actually i want if return rows result is 0 then all textfields would be read only.

Thank you in advance!


Answers (4)