0

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();
4
Contributors
6
Replies
26
Views
2 Years
Discussion Span
Last Post by isozworld
0

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

Convert.ToDecimal(descd.Text);

0

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

Edited by kidkardel

0

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.

0

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();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.