Sqlexception was occured?

Posted by Sudheep.grandhe under C# on 11/14/2011 | Points: 10 | Views : 1068 | Status : [Member] | Replies : 1
Hi,

I've the following error in my code.can you please rectify this error.please do the needful.
Error:-
Error converting data type nvarchar to bigint.
public void getdata()
{
string strondate, strinvoicedate;
//int id = Convert.ToInt32(label5.Text.ToString());
DataTable dt=new DataTable ();
SqlConnection con=new SqlConnection ("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd=new SqlCommand ("select compname,compaddress,invoiceno,orderno,ondate,invoicedate,netamount,netvat,tamount from tbl_Report2 WHERE invoiceno=@invoiceno ",con );
SqlDataAdapter da=new SqlDataAdapter (cmd );
//SqlParameter prm=new SqlParameter("@invoiceno",label4.Text );
cmd.Parameters.AddWithValue("@invoiceno",label8 .Text );
da .Fill (dt );//Error shows here as:- Error converting data type nvarchar to bigint.
if (dt .Rows .Count > 0 )
{
label2.Text =dt.Rows[0]["compname"].ToString ();
label3 .Text =dt .Rows [0]["compaddress"].ToString ();
label8 .Text =dt.Rows [0]["invoiceno"].ToString ();
label9 .Text =dt.Rows [0]["orderno"].ToString ();
strondate =dt.Rows [0]["ondate"].ToString ();
if (strondate !="null" )
{
char [] separator=new char [] { ' ' };
string [] s1=strondate .Split (separator );
string date=s1 [0].ToString ();
label10 .Text =date ;
}
strinvoicedate =dt .Rows [0]["invoicedate"].ToString ();
if (strinvoicedate !="null")
{
char []separator=new char[] { ' ' };
string[] s1= strinvoicedate .Split (separator );
string date=s1 [0].ToString ();
label11 .Text =date;
}
label15 .Text =dt .Rows [0]["netamount"].ToString ();
label16 .Text =dt.Rows [0]["netvat"].ToString ();
label17 .Text =dt .Rows [0]["tamount"].ToString ();
}
con .Close ();
}

Best,
Sudheep.



Responses

Posted by: SheoNarayan on: 11/14/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
The error is self explanatory.

Error converting data type nvarchar to bigint.

It says that it is not able to convert nvarchar to bigint. You have can use the Intermediate window while debugging step by step (use F10) and get the value of each variable you are passing in as the input to the SQL Server.

This looks simply data conversion problem.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response