Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know where is the problem, but do not know how to fix it.

Column that gives me the error in the database is tipe "NUMBER" and accept null values​​.

But when execute query ....
C#
Program.Connection.CommandText = "select Contracts.ContractId, Contracts.StartDate, Contracts.EndDate, Contracts.Procent, ContractItems.DeletedId AS ContracteActive, sum (ContractItems.Payment) AS Total_Platit, Now () AS DataCurenta from Contracts INNER JOIN ON ContractItems Contracts.ContractId = ContractItems.ContractId WHERE ClientID = @ ClientID "
                 + "GROUP BY Contracts.ContractId, Contracts.StartDate, Contracts.EndDate, Contracts.Procent, ContractItems.DeletedId ORDER BY Contracts.EndDate AND (((ContractItems.DeletedId) Is Null)), Contracts.EndDate DESC";
             Program.Connection.AddParameter ("@ ClientID", ClientID.Text);

the query when it finds a record that has null field, it gives me this error, how to read data whether that field is null or contain a number.?
Posted
Updated 7-Sep-12 6:56am
v2
Comments
[no name] 7-Sep-12 10:22am    
The error that yo are getting has nothing to do with nulls but with type mismatch. It seems that it is expecting int32 and you are passing it something else.

Do you need those data where DeleteId is null? If not, you could add a WHERE statement like
SQL
WHERE ContractItems.DeletedId is not null
before the Group By clause.
But I have some doubts... Is ClientId also a number - and the TextBox ClientId contains other characters?
You could replace the line with e.g.
C#
Program.Connection.AddParameter ("@ClientID", Convert.ToInt32(ClientID.Text));
 
Share this answer
 
Comments
Aciobanita Costel 7-Sep-12 10:57am    
Yes, I need data whre DeleteId is null, or have a number.
ClientId is also a number, but is declared like:

.....

ClientID.Text = cboNumeClient.SelectedValue.ToString();

....
Bernhard Hiller 7-Sep-12 13:20pm    
Then use COALESCE for that column. It's something like
COALESCE(ContractItems.DeletedId, -1) AS ContracteActive
and then use "ContracteActive" in the respective position in the Group By clause.
it's better u check with ISNULL function.
ISNULL(parameter, 0). in this if the parameter is null then the result is 0 else the value will be refelected.
 
Share this answer
 
Comments
Aciobanita Costel 7-Sep-12 11:05am    
I try this, but it give a error:

Wrong number of arguments used with function in query expression

'ISNULL(ContractItems.DeletedId,0)'.

i use microsoft access for database
You should check TextBox.Text before your code.
The TextBox.Text must convertable to Int32. If it contains any letter you would expect this error.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900