Failed to convert nvarchar value 'VINET' to int data type

0

I have this error:

Falha ao converter o nvarchar valor 'VINET' para o tipo de dados int.

Below my code:

private void button1_Click(object sender, EventArgs e)
        {
            try 
            {
                SqlConnection dataConnection = new SqlConnection();

                dataConnection.ConnectionString = ConfigurationSettings.AppSettings["consBanco"].ToString();

                string sql = "SELECT * " +
                              "FROM Orders WHERE CustomerID = @CustomerIdParam";

                dataConnection.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = sql;
                cmd.Connection = dataConnection;
                cmd.CommandType = CommandType.Text;

                //SqlParameter param = new SqlParameter("@CustomerIdParam", SqlDbType.Char, 5);
                //param.Value = customerID;
                //cmd.Parameters.Add(param);
                cmd.Parameters.AddWithValue("@CustomerIdParam", 1);

                // cria o dataadapter...
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = cmd;

                // preenche o dataset...
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                grdTeste.DataSource = dataSet;
                grdTeste.DataMember = dataSet.Tables[0].TableName;


            }
            catch (SqlException ex)
            {

            }
        }
    
asked by anonymous 30.06.2014 / 00:58

2 answers

1

It was resolved as follows. I put an ExecuteReader and it worked out there. Another thing, the DB column was wrong, it was nchar and so I was giving the VINET error. I made a mistake for lack of attention.

    
08.07.2014 / 03:17
0

The error occurs because your grdTeste is expecting a column named VINET , represented by an integer, but that the bank column is represented by nvarchar or some similar data type.

Change the column VINET from grid to String that the problem will be solved.

    
30.06.2014 / 05:15