?
Solved

DataAdapter "No value given for one or more required parameters."

Posted on 2010-01-08
11
Medium Priority
?
654 Views
Last Modified: 2013-11-17
I have a program that loads some data from a text file using the following code:

oledbOrderFile.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data Source=\\<dir>\<subdir>;Mode=ReadWrite;Extended Properties="text;HDR=No;FMT=Delimited(|)"

Dim sql As String = "SELECT F1 as POType, F2 as PONum, ..., F54 as ProductLine, , F55 as AddDesc, F56 as UnitSize FROM [Temp#txt]"

Dim cmd As New OleDb.OleDbCommand(sql, oledbOrderFile)
Dim da As New OleDb.OleDbDataAdapter(cmd)
da.Fill(dsBasicData, "Custom")

Now I need to add 2 fields to the sql, which doesn't seem like that big of a deal, but for some reason I get the following error on the da.Fill(dsBasicData, "Custom"):
"No value given for one or more required parameters."

I have all the fields defined in the columns of the datatable, and the tablemapping in the dataadapter.  I am not sure what I would be missing.

I also tried just loading it as:
Dim sql As String = "select * from [Temp#txt]"
which added the fields at the end of the defined fields, but still not the last 2 fields.

Any ideas what the problem may be?
Thanks.
0
Comment
Question by:juliemckenzie
  • 7
  • 4
11 Comments
 
LVL 7

Expert Comment

by:DanSo1
ID: 26283491
Are you using DataSet?
If so, then try to delete DataAdapter and create it as new.
0
 

Author Comment

by:juliemckenzie
ID: 26284705
I just realized I am not using the dataadapter that had the table mappings.  I am using a dataset, and I tried just loading it to a datatable within it that does not have defined fields, and I still am not getting the last 2 fields (only 54).  Is there a limit with this type of connection?

My code now looks like this:
            Dim sql As String = "select * from [Temp#txt]"
            Dim cmd As New OleDb.OleDbCommand(sql, oledbOrderFile)
            Dim da As New OleDb.OleDbDataAdapter(cmd)
            da.Fill(dsBasicData, "ASeries")
0
 
LVL 7

Expert Comment

by:DanSo1
ID: 26286725
No, there is no limit.
Why don't you try to add dataset to the project and then add dataadapter? You can try if your statement working at design time.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:juliemckenzie
ID: 26292836
I am trying that, but still no luck.
0
 
LVL 7

Expert Comment

by:DanSo1
ID: 26292868
Could you give us example of your data file?
0
 

Author Comment

by:juliemckenzie
ID: 26292993
I have attached a test file with just one line.
Test1.txt
0
 

Author Comment

by:juliemckenzie
ID: 26293142
Actually, I probably should have attached the temp file, since that is the actual file used at this point in the code (Test1.txt is copied to Temp.txt earlier in code).
Temp.txt
0
 

Author Comment

by:juliemckenzie
ID: 26294914
Funny thing is when I changed the name of the file to Temp2.txt, it imported all the data to 1 column.  when I changed it back to Temp.txt, it imported 54 columns.  Both times the sql was the same:
"select * from Temp.txt" or "select * from Temp2.txt".  Could there be somewhere that is defining the columns of this file that I don't know about?
0
 
LVL 7

Expert Comment

by:DanSo1
ID: 26301085
One thing: setting HDR=NO  means that you don't have field names in first row. So statement "select *" will never work becouse we don't have column names.
0
 

Author Comment

by:juliemckenzie
ID: 26304030
OK.  That makes sense.  So I am back to listing each of the fields to select as originially ("SELECT F1 as POType, F2 as PONum, ..., F54 as ProductLine, , F55 as AddDesc, F56 as UnitSize FROM [Temp#txt]") and I still get the error "No value given for one or more required parameters".  It is not pulling those last 2 fields.  I can't see anywhere though where the other fields are defined.
0
 

Accepted Solution

by:
juliemckenzie earned 0 total points
ID: 26307416
I finally got it!  There was a schema.ini file with the 54 fields defined for Temp.txt.  Once I added the 2 additional fields, it worked.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question