059f66a5bfcd6a29caa513f06d6ee5d1

Hello again, I am now encountering the above problem.
i dunno what to do and tried everything.
my Column for Capital is decimal so i dunno why it is saying varchar.
my codes are

 con.ConnectionString = //insert data source;
  if (con.State != ConnectionState.Closed)
            {
                con.Close();
            }
            cmd.Connection = con;
  cmd.CommandText = "SELECT CAPITAL FROM TblProduct WHERE Description='" + descd.Text + "'and Price='" +upd.Text + "'";
            con.Open();
            dr = cmd.ExecuteReader();
             int cap_d = dr.GetOrdinal("CAPITAL");
            while (dr.Read())
            {
                cap_dvalue.Text = Convert.ToString(dr[cap_d]);
            }
                con.Close();
            dr.Close();

It's because you trying to put a string, descd.Text, into your decimal parameter without converting it.

Convert.ToDecimal(descd.Text);

But my description column is a string so I am calling it by a string, my capital is the one oon decimal also my description is not a number

Sorry I completely missread your code.

As depicted above. try inserting a breakpoint in your code on line 7

cmd.CommandText = "SELECT CAPITAL FROM TblProduct WHERE Description='" + descd.Text + "'and

Hover over the CommandText and look for a magnifying glass. Copy and paste the code into SQL and try executing it there and see if it runs without errors.

Change your code like below

 con.ConnectionString = //insert data source;
  if (con.State != ConnectionState.Closed)
            {
                con.Close();
            }
            cmd.Connection = con;
  cmd.CommandText = "SELECT CAPITAL FROM TblProduct WHERE Description='" + descd.Text + "'and Price='" +upd.Text + "'";
            con.Open();
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                cap_dvalue.Text = dr.GetString(0);
            }
                con.Close();
            dr.Close();

And also, close your dataReader before connection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.