Hi guys ,
I'm trying to retrive some values from two different tables(SQL) but I get generall exception error.
What I mean is I have table sales and table item_sales
with the following code I retrive the correct values from variables that i need
protected string InputId { get; set; }
protected string InputValue { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
SqlCommand sqlCommand = new SqlCommand("select id_product,price from item_sales where id_sales=(select max(id_sales) from item_sales)", con1);
con1.Open();
using (SqlDataReader read = sqlCommand.ExecuteReader())
{
while (read.Read())
{
string id_product = read["Id_product"].ToString();
string price = read["price"].ToString();
this.InputId = id_product;
}
read.Close();
}
con1.Close();
But I need in the same page if that is possible to retrieve the full price item so i add the following code
SqlCommand sqlCommand2 = new SqlCommand("select price_item from sales where id_sales=(select max(id_sales) from sales)", con1);
con1.Open();
using (SqlDataReader read2 = sqlCommand.ExecuteReader())
{
while (read2.Read())
{
string total_cart_price = read2["price_item"].ToString();
this.InputValue = total_cart_price;
}
read2.Close();
}
con1.Close();
but i receive an error "IndexOutOfRangeException was unhandled by user code"
Is any way to retrieve values from two different tables? and how?
Thnx in advance for yours Time!
Jason!