Question error in saving the record into MSACCESS database

swethajain

Well-known member
Joined
Feb 1, 2010
Messages
48
Programming Experience
Beginner
HI,
I have 3 comboboxes and some textboxes. when the form is intialised the comboxes will be loaded with data from the database, but when iam saving the records comboxes records are getting saved as system.data.datarowview in the database. can anyone tell me what is the problem?

Imports System.Data.OleDb

Public Class HT_Insert
Dim myConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='h:/info2.mdb'")
Dim myCommand As OleDbCommand
Dim ra As Integer
Dim result As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strSQL As String = "SELECT * FROM Region"
Dim da As New OleDbDataAdapter(strSQL, myConnection)
Dim ds As New DataSet
da.Fill(ds, "Region")

With cbx_Region
.DataSource = ds.Tables("Region")
.DisplayMember = "Reg"
.ValueMember = "ID"
.SelectedIndex = -1
End With

Dim strSQL1 As String = "SELECT * FROM ConstructionPackage"
Dim da1 As New OleDbDataAdapter(strSQL1, myConnection)
Dim ds1 As New DataSet
da1.Fill(ds1, "ConstructionPackage")

With cbx_ConPack
.DataSource = ds1.Tables("ConstructionPackage")
.DisplayMember = "ConPack"
.ValueMember = "ID"
.SelectedIndex = -1
End With
Dim strSQL2 As String = "SELECT * FROM Trade"
Dim da2 As New OleDbDataAdapter(strSQL2, myConnection)
Dim ds2 As New DataSet
da2.Fill(ds2, "Trade")

With cbx_Trade
.DataSource = ds2.Tables("Trade")
.DisplayMember = "Trade"
.ValueMember = "ID"
.SelectedIndex = -1
End With
tb_Resource.Text = Environment.UserName.ToString()
Me.Text = Me.Text & " User: " & Environment.UserDomainName & "\" & Environment.UserName
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As String = DateTimePicker1.Text
Dim re As String = tb_Resource.Text
Dim cp As String = cbx_ConPack.SelectedItem.value.ToString
Dim rg As String = cbx_Region.SelectedItem.value.ToString
Dim tr As String = cbx_Trade.SelectedItem.value.ToString
Dim lo As String = TextBox3.Text
Dim nn As String = TextBox4.Text
Dim ta As String = tb_Task.Text
Dim pr As String = tb_Percent.Text
Dim du As String = tb_HRS.Text
Dim ass As String = TextBox8.Text

Try
myConnection.Open()
Dim str As String = "insert into Record([Dt],[Res],[Construction Package],[Region],[Trade],[Location],[Network Name],[Task],[Progress],[Duration],[Assumptions])values ('" & dt & "','" & re & "','" & cp & "','" & rg & "','" & tr & "','" & lo & "','" & nn & "','" & ta & "','" & pr & "','" & du & "','" & ass & "')"
Dim cmd As New OleDbCommand(str, myConnection)
ra = cmd.ExecuteNonQuery()
If (ra > 0) Then
result = MsgBox("Record Inserted", MsgBoxStyle.Information, "Message Box")
End If
myConnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
For Each ctrl As Control In Me.Controls
If ctrl.GetType.Name = "TextBox" Then ctrl.Text = ""
If ctrl.GetType.Name = "ComboBox" Then ctrl.Text = ""
Next
tb_Resource.Text = Environment.UserName.ToString()
End Sub


Thanks,
Swetha
 
>>cbx_ConPack.SelectedItem.value.ToString

Try cbx_ConPack.Text or cbx_ConPack.SelectedText. I believe the ".SelectedItem.value.ToString" would cause this if my memory serves.
 
Back
Top