Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
edited tags
Link
p.s.w.g
  • 149.6k
  • 31
  • 307
  • 339
formatting, spelling, tags
Source Link
p.s.w.g
  • 149.6k
  • 31
  • 307
  • 339

I have a database in which iI created a table HUGGO_BOSS,itsHUGO_BOSS. Its columns are [brand name][brand name], [stock quantity] [stock quantity], [retail price][retail price] and its primery key is [Brand name][Brand name]. I want to fill my textbox in windows form with the value of stock quantity present in my database  .I I tried the following code but it gives run-time error on runtime that "The Connection was not close, the connection state is open". One more thing, here i wil select the primary key by using a combobox3

The Connection was not close, the connection state is open.

 if (comboBox2.Text == "HUGO BOSS")  {   try   {   OleDbCommand cmd = con.CreateCommand();   cmd.CommandText = "Select [Stock quantity] as stockquantity from HUGO_BOSS WHERE [Brand name]=@name";   cmd.Parameters.AddWithValue("@name", comboBox3.SelectedItem);   con.Open();   OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleResult);   if (dr.Read())   {     textBox7.Text = dr["stockquantity"].ToString();   }     }   finally { con.Close(); }  } 

One more thing, here I will select the primary key by using a combobox3

I have a database in which i created a table HUGGO_BOSS,its columns are [brand name], [stock quantity] , [retail price] and its primery key is [Brand name]. I want to fill my textbox in windows form with the value of stock quantity present in my database  .I tried the following code but it gives error on runtime that "The Connection was not close, the connection state is open". One more thing, here i wil select the primary key by using a combobox3

 if (comboBox2.Text == "HUGO BOSS")  {   try   {   OleDbCommand cmd = con.CreateCommand();   cmd.CommandText = "Select [Stock quantity] as stockquantity from HUGO_BOSS WHERE [Brand name]=@name";   cmd.Parameters.AddWithValue("@name", comboBox3.SelectedItem);   con.Open();   OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleResult);   if (dr.Read())   {     textBox7.Text = dr["stockquantity"].ToString();   }     }   finally { con.Close(); }  } 

I have a database in which I created a table HUGO_BOSS. Its columns are [brand name], [stock quantity], [retail price] and its primery key is [Brand name]. I want to fill my textbox in windows form with the value of stock quantity present in my database. I tried the following code but it gives run-time error

The Connection was not close, the connection state is open.

if (comboBox2.Text == "HUGO BOSS") { try { OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = "Select [Stock quantity] as stockquantity from HUGO_BOSS WHERE [Brand name]=@name"; cmd.Parameters.AddWithValue("@name", comboBox3.SelectedItem); con.Open(); OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleResult); if (dr.Read()) { textBox7.Text = dr["stockquantity"].ToString(); } } finally { con.Close(); } } 

One more thing, here I will select the primary key by using a combobox3

Source Link
user3043233
user3043233

How to fetch data from access database in a textBox using C#

I have a database in which i created a table HUGGO_BOSS,its columns are [brand name], [stock quantity] , [retail price] and its primery key is [Brand name]. I want to fill my textbox in windows form with the value of stock quantity present in my database .I tried the following code but it gives error on runtime that "The Connection was not close, the connection state is open". One more thing, here i wil select the primary key by using a combobox3

 if (comboBox2.Text == "HUGO BOSS") { try { OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = "Select [Stock quantity] as stockquantity from HUGO_BOSS WHERE [Brand name]=@name"; cmd.Parameters.AddWithValue("@name", comboBox3.SelectedItem); con.Open(); OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleResult); if (dr.Read()) { textBox7.Text = dr["stockquantity"].ToString(); } } finally { con.Close(); } }