[Solved] ASP.Net Error: Conversion failed when converting the varchar value BL-10002 to data type int

akhter
 
on Nov 23, 2021 03:38 AM
638 Views

When i am inputing BL-10002 into textbox, then below error is coming

Conversion failed when converting the varchar value BL-10002 to data type int

<asp:TextBox ID="txtsearcbn" runat="server" AutoPostBack="true" Height="24px" OnTextChanged="txtsearcbn_TextChanged"  Width="127px"></asp:TextBox>

C#

String strQuery = "Sp_Retrive_Bale_for_Dispatch";
SqlCommand cmde = new SqlCommand();
cmde.Parameters.AddWithValue("@Bale_ID", txtsearcbn.Text.Trim());
cmde.CommandType = CommandType.StoredProcedure;
cmde.CommandText = strQuery;
cmde.Connection = con;
try
{
    con.Open();
    SqlDataReader sdr = cmde.ExecuteReader();
    while (sdr.Read())
    {
        lbid.Text = sdr["Bale_ID"].ToString();
        ddlitem.SelectedValue = sdr["item_code"].ToString();
        txtqty.Text = sdr["Bale_Qty"].ToString();
        txtwht.Text = sdr["Bale_Weight"].ToString();
        txtdno.Text = sdr["D_ID"].ToString();
    }

 

ALTER Proc  [dbo].[Sp_Retrive_Bale_for_Dispatch]
    @Bale_ID varchar(15) 
as 
begin
    select Bale_ID,item_code,Bale_Qty,Bale_Weight,D_ID 
    From tbl_Bale_Prd 
    where  Bale_ID = @Bale_ID and (D_ID IS NULL or D_ID=1)

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Nov 23, 2021 10:03 PM

What is the datatype of Bale_ID?

Share sample record of tbl_Bale_Prd.

Bale_ID datatype is int and you are comparing int column with alphanumeric value. So the error.