Hi everybody,
I need some help with my project.
I'm trying to retrieve some data from a combo box on which i used the "data bound item task" so I can select data from a table of my database.
the problem I'm having is that when i try to save into another table the selected item from the combo box.....either I get an error "failed to convert parameter value from a DataRowView to a string" or it just save the field of the table in blank
here is the code
[code=vb]
Dim queryAddCurso As String
queryAddCurso = " INSERT INTO Curso_Semestre (SECCION, CODIGO, NOMBRE_CURSO, CREDITO) VALUES (@SECCION,@CODIGO,@NOMBRE_CURSO,@CREDITO)"
Dim cmd As New SqlCommand(queryAddCurso, getConnection())
Try
cmd.Parameters.Add(New SqlParameter("@SECCION", SqlDbType.NVarChar, 10))
cmd.Parameters.Add(New SqlParameter("@CODIGO", SqlDbType.NVarChar, 10))
cmd.Parameters.Add(New SqlParameter("@NOMBRE_CURSO", SqlDbType.NVarChar, 80))
cmd.Parameters.Add(New SqlParameter("@CREDITO", SqlDbType.NChar, 1))
cmd.Prepare()
cmd.Parameters("@SECCION").Value = SECCIONTextBox.Text
cmd.Parameters("@CODIGO").Value = CODIGOComboBox.SelectedText.ToString ' --->this way it save the field in blank
cmd.Parameters("@NOMBRE_CURSO").Value = NOMBRE_CURSOComboBox.SelectedItem.ToString '---> this way it save into the field "System.Data.DataRowView" & if I don't use the .ToString i get the error above.
cmd.Parameters("@CREDITO").Value = CREDITOComboBox.SelectedItem
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
MsgBox("Data Write Successfully", MsgBoxStyle.OkOnly, "Saved Info")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "InsertDataError_cursoXsemestre")
End Try
End Sub