database insertion problem

aniskhan

Well-known member
Joined
Oct 24, 2005
Messages
90
Location
D.I.Khan
Programming Experience
1-3
I have the DB "imdb" in access having one field "path" text.

here i ADD the path(got it through opendialog) into the DB.
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim currFldr As String	
	'copy the fullpath
        If Me.OpenFileDialog1.ShowDialog = DialogResult.OK Then
            currFldr = New DirectoryInfo(Me.OpenFileDialog1.FileName).ToString
        End If

        Me.OleDbConnection1.Open()
        Me.DataSet11.Clear()

	'Addnew path
        Me.BindingContext(DataSet11, "imdb").AddNew()

	
        Dim newRow As DataRow = DataSet11.imdb.NewRow
	
	'copy new value in dataRow
        newRow("path") = currFldr
        Me.DataSet11.Tables("imdb").Rows.Add(newRow)

        Me.OleDbDataAdapter1.Update(DataSet11)

        Me.OleDbConnection1.Close()

End Sub

the problem..
path (from opendialog is alright) but when ADD in database it not the complete path (lost last characters)

i checked newRow("path") created ,but it has the complete path

VB.NET:
Label1.Text = newRow("path")

anythg wrong in code..
 
for starters it's not a good idea to use keywords as variables i.e

Dim newrow as datarow = ......

It can be quite confusing to read and not a good habit to get into.

Secondly it may be a case of certain characters in the string that could be causing the problem.

Thirdly you don't have to explicitly close an oledbconnection when using the a dataadapter. it does all that for you whether there was an error or not.
 
Back
Top