Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim cmdg As OleDbCommand
Dim sqlr As String
Dim sqlra As New OleDbCommand
Dim conb = New OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;data source=inbound.mdb")

       sqlr = "Insert Into ManualDO (BLNo,DONo,ReleaseTo,Vessel,Voyage,FromPort,ETA,NoCont,Weight,Measure) Values ('" & IIf(rd1![NoBL] = "", " ", rd1![NoBL]) & "' , '" & Strings.Right(IIf(rd1![MNoBL] = "", rd1![NoBL], rd1![MNoBL]), 7) & "','" & tempCust & "','" & IIf(UCase(rd1![NMAngk]) = "", " ", UCase(rd1![NMAngk])) & "',V. '" & rd1![NoVoy] & "','" & IIf(Trim(rd1![NMPort]) = "", " ", Trim(rd1![NMPort])) & "','" & Format(rd1![TGTiba], "MMMM DD YYYY") & "','" & IIf(NoCont = "", " ", NoCont) & "','" & Format(Trim(str(rd1![Bruto])), "###,##0.000") & " KGS','" & Format(Trim(str(rd1![Volume])), "###,##0.000") & " M3')"

cmdg = New OleDbCommand(sqlr, conb)
conb.Open()
sqlra = New OleDbCommand(sqlr, conb)
sqlra.ExecuteNonQuery()


Could you help me whats the matter with this code ?
That error appear in line sqlr query.
Thanks before
Posted

1 solution

No. We can't.

The simple reason is that you are doing two things wrong: firstly you are concatenating strings to form an SQL command, which is extremely dangerous - it leave you wide open to SQL Injection attacks which can damage or destroy your database. Use parametrized queries instead.

Secondly, it's down to your data: and we don't have access to that. So use the debugger. Put a breakpoint on the line, and examine each part of the statement in turn when it hits the breakpoint. When you find which part is null, you can start looking back in your cdoe to find out why. But we can't!
 
Share this answer
 
Comments
Member 11182846 29-Oct-14 5:52am    
So the matter is my query are not in right written part. Is it right ? Or anything else so it become error ?
OriginalGriff 29-Oct-14 5:55am    
The query is wrong, in that it's dangerous to do it that way - doesn't mean it won't work, just that anyone, anywhere, can do anything they like to your DB by manipulating the data you are using.

The problem is (probably) somewhere else in your code: it's just showing up here. You need to look at the data in the debugger to find out exactly what part of it is null (or Nothing in VB) and find out how and why it got there with a null value. We can't do that, because we can't run your code!

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