Newbie: error trying to save directory path to database

K

Keith R

I'm working on an windows application (vb.net express, SQL express) where I
want to store a path and filename (separately) in a database, then be able
to click on a row in the DataGridView to have the app load the file. In
order to populate the source table in the first place, I have a button that
recursively searches directories to find files of the appropriate type, and
put that data into the table. Unfortunately, it isn't quite working.
Relevant pieces of code are below; the error I'm getting is:
Cannot set column 'Clip_FilePath'. The value violates the MaxLength limit
of this column.
The actual filepath value when the error occurs (the first file it finds)=
"C:\Documents and Settings\Owner\Desktop\VB test video files"
In the database explorer tab, table definition: Clip_filepath is
varchar(500)
I refreshed and saved everything, and even restarted VB.net and still no
love.

Here is the relevant code; any help would be greatly appreciated. I'll post
separately if I can't figure it out once my table is populated, but my next
step will be to figure out how to avoid adding a row (in the code below) if
the local_ID is already in the database.
Thanks!
Keith

.....
ApexPath = folderDialog.SelectedPath

If Len(ApexPath) > 0 Then
For Each FileFound As String In Directory.GetFiles(ApexPath, "*.avi")
'***FILEINFO CLASS***
Dim fi As FileInfo = New FileInfo(FileFound)
Dim dt_fi As Date = fi.CreationTime
Dim sz_fi As Long = fi.Length
Dim ConvertedFileDate As String
Dim ConvertedFileTime As String

newMasterRow.Clip_Text_Description = ""
newMasterRow.Clip_FilePath = Path.GetDirectoryName(FileFound)
newMasterRow.Clip_FileName = Path.GetFileName(FileFound)
newMasterRow.Clip_Length = sz_fi

'populate MonkeyMain.Local_ID
ConvertedFileDate = Convert.ToString(Format(dt_fi, "yyyyMMdd"))
ConvertedFileTime = Convert.ToString(Format(dt_fi, "HHmmss"))
newMasterRow.Local_ID = ConvertedFileDate & ConvertedFileTime & "_" &
Convert.ToString(sz_fi)

'this is where I get the error
Me.MonkeyMasterTableDataSet.MonkeyMain.Rows.Add(newMasterRow)

Thanks for any assistance!
Keith
 
K

Ken Tucker [MVP]

Hi,

Two things. First try setting the max length for the column to 500

MonkeyMasterTableDataSet.MonkeyMain.Column("Clip_filepath").MaxLength=500

Second declare newMasterRow inside of the for each loop or you will get an
error about the row already being added.

Ken
 
K

Keith R

Ken- thank you- this helped identify that whatever is going in, it is more
complicated than I thought... and additional help would be appreciated.

I moved the Dim newMasterRow inside the loop as you suggested (thank you)
but when I added the maxlength line, I get the error:
'column' is not a member of
'mymoviecollection1.monkeymastertabledataset.monkeymaindatatable'.

I started this project with the mymoviecollection sample app, and have made
major modifications- I didn't think that there were still any references to
mymoviecollection at all, other than the old resource files (for button
faces)...I even searched to make sure i hadn't missed any. The only tables
in my project are (in MonkeyMasterTableDataSet): FlagButtonText,
MonkeyFlags, and MonkeyMain (which has a linked copy of MonkeyFlags in the
Data sources window, presumably due to a foreign key). Same in my Database
Exlporer/Data connections- I only have my three tables, and one database
diagram to show the foreign key link.

Since I'm not sure where it would be getting a mymoviecollection reference,
where else should I be looking (to get rid of it, as appropriate)? I'm
assuming that whatever is going on must be related to my original problem
adding rows.

Thank you again,
Keith
 
K

Keith R

Nevermind, I got it :)
Still not sure why it was referencing mymoviecollection, but at least it is
working now.
Thanks,
Keith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top