Click here to Skip to main content
15,886,059 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
private void btn_addtostore_Click(object sender, EventArgs e)
        {
            string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\StoreProdcut.mdb";
            string sqlStr = null;
            OleDbConnection conn = null;
            OleDbCommand cmd = null;
            int[] id = new int[8];
            int k = 0;

            if (Chk_DolceBlack.Checked == true)
            {
                id[k] = 0;
                k++;
            }

            if (Chk_CarvenBlackWhite.Checked == true)
            {
                id[k] = 1;
                k++;
            }

            if (Chk_StellaBlackWhite.Checked == true)
            {
                id[k] = 2;
                k++;
            }

            if (Chk_DolceYellow.Checked == true)
            {
                id[k] = 3;
                k++;
            }

            if (Chk_CarvenBlueGreen.Checked == true)
            {
                id[k] = 4;
                k++;
            }

            if (Chk_StellaPurple.Checked == true)
            {
                id[k] = 5;
                k++;
            }

            if (Chk_DolceGreen.Checked == true)
            {
                id[k] = 6;
                k++;
            }

            if (Chk_CarvenYellowBlue.Checked == true)
            {
                id[k] = 7;
                k++;
            }

            if (Chk_StellaBlue.Checked == true)
            {
                id[k] = 8;
                k++;
            }

            {
                id[k] = 8;
                k++;
            }
  
                 try 
            {
                conn = new OleDbConnection(connStr);
                sqlStr = string.Format("SELECT Brand, Color, Price FROM Dresses Where ID='0'");
                cmd = new OleDbCommand(sqlStr, conn);
                conn.Open();
                cmd.ExecuteNonQuery();                       

                int i;
                string s;

                 for (i = 0; i < k; i++)
                {
                     if (i==0)
                         s = sqlStr+"ID="+id[k];
                    else
                         s = sqlStr+"and ID="+id[k];
                }

            }
            catch (Exception err) // catch any exceptions
            {
                MessageBox.Show(err.Message);
            }

                 frm_7 rc = new frm_7(sqlStr);
                 rc.Show();
                 rc.Activate();

                   }
         private void btn_Store_Click(object sender, EventArgs e)
         {

         }

          private void button1_Click(object sender, EventArgs e)
         {
            new frm_8().Show();
            this.Hide();
             }





//-----------------------------------------

        private void btn_Buy_Click(object sender, EventArgs e)
        {
            //this.dressesTableAdapter1.Fill(this.storeProdcutDataSet1.Dresses);

            string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\StoreProdcut.mdb";
            string sqlStr = null;
            OleDbConnection conn = null;
            OleDbCommand cmd = null;
            OleDbDataReader data = null;

            try
            {
                // open database connection. Setup the SQL statement to show courses new student 
                // is in, in the studentcousrses table and execute statement
                conn = new OleDbConnection(connStr);
                sqlStr = string.Format("SELECT Brand, Color, Price FROM Dresses Where ID='0'");
               
                cmd = new OleDbCommand(sqlStr, conn);
                conn.Open();
                data = cmd.ExecuteReader();
                while (data.Read())
                {
                    lst_result.Items.Add((string)data.GetString(1) + (string)data.GetString(2) + (string)data.GetString(3));
                }
            }
            catch (Exception err) // catch any exceptions
            {
                MessageBox.Show(err.Message);
            }
        }
    }
}
Posted
Updated 13-Jun-14 21:51pm
v2
Comments
phil.o 14-Jun-14 3:54am    
This is just a code dump, with an error statement as title, but you never actually decribe precisely where the error is occuring.
Would you mind posting us the complete exception message, along with its stack trace?
Richard MacCutchan 14-Jun-14 3:59am    
You have coded
sqlStr = string.Format("SELECT Brand, Color, Price FROM Dresses Where ID='0'");
Are you sure the ID field is a character and not some integer type?
future2015 14-Jun-14 5:33am    
where is error occured?

1 solution

Hello friend, it seems like you are getting datatype mismatch error as you're trying to concatenate string with an integer value. Try to convert the integer value to string as shown below:
C#
for (i = 0; i < k; i++)
{
  if (i==0)
    s = sqlStr+"ID="+id[k].ToString();
  else
    s = sqlStr+"and ID="+id[k].ToString();
}

- DD
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900