0
I have that mistake:
Falha ao converter o nvarchar valor 'VINET' para o tipo de dados int.
Down with 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)
{
}
}
Only with this information is difficult to help. Where is giving this error. There is no VINET in your code, where does it come from? You know this
catch
You’re just making it hard to figure out what the mistake is? Here is a start and a number of links (p/ C#) to better understand the operation of exceptions (not so specific p/ Java): http://answall.com/questions/21933/comond-trata-exce%C3%A7%C3%B5es-em-java/21939#21939– Maniero
Is this mistake weird, is it in Portuguese? Anyway, this VINET that you don’t have in your code is a text (
nvarchar
in the SQL nomenclature orstring
in C#) and where the error is waiting for aint
, then you have to convert it probably withint.Parse(VINET.Text)
, but it is an assumption since there is not enough information. Or you can make aCAST
in SQL but doubt that’s what you need.– Maniero
When I try to load the grid, it gives the wrong message in catch. Not the slightest idea where this error is happening. What I want is to fill a grid. I couldn’t do it with Datareader and so I used Sqldataadapter and I don’t know if that’s it.
– user11844
You have no idea why you’re killing the mistake with the
catch
. Did you read what I gave you? I know, it’s a lot, but if you don’t understand how exceptions work and keep using them wrong, your life is gonna get complicated. And if even you do not know what is happening with your application, random people on the internet have even less chance to know. I am waiting for you to give better information. Or you are waiting for someone who has had an identical problem that can help you. Nothing else appears on the screen, just this error message?– Maniero