Jump to content

[Resolvido] guarda na BD mas dá erro


AnaGPSI
 Share

Recommended Posts

Tenho o seguinte código:

    'If ComboBox2.Text = "" Or combodiscimodular.Text = "" Or TextBox2.Text = "" Or txtnomealuno1.Text = "" Or combomodmodular.Text = "" Or ComboBox5.Text = "" Or ComboBox6.Text = "" Or TextBox6.Text = "" Or ComboBox7.Text = "" Then
    '    MsgBox("Existem campos vazios. Preencha os campos em branco!")
    'Else
    '''''''''''''''''''''''''''''''''''''''''''

    Dim a, b, c, sql As String
    a = ComboBox2.Text
    b = combodiscimodular.Text
    c = ComboBox7.Text

    Dim connetionString As String
    Dim oledbCnn As OleDbConnection
    Dim oledbCmd As OleDbCommand
    Dim cod_disc As Integer
    connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\GPSI\Documents\mydb.accdb;"
    Dim nome_disciplina = combodiscimodular.SelectedItem
    Dim mydb As New OleDbConnection(connetionString)
    mydb.Open()
    '''''''''''código da disciplina selecionada na combobox''''''''
    sql = "select * from disciplina where nome_disci='" & combodiscimodular.Text & "'"
    oledbCnn = New OleDbConnection(connetionString)
    oledbCnn.Open()
    oledbCmd = New OleDbCommand(sql, oledbCnn)
    Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader()
    While oledbReader.Read
	    cod_disc = oledbReader.Item(0)
    End While
    oledbReader.Close()
    oledbCmd.Dispose()
    oledbCnn.Close()
    'MsgBox(cod_disc)
    '''''''''''''''''''''''''''''''''''''''''''
    Dim oledbCnn1 As OleDbConnection
    Dim oledbCmd1 As OleDbCommand
    Dim cod_mod As Integer
    sql = "select * from modulos where nome_mod='" & combomodmodular.Text & "'"
    oledbCnn1 = New OleDbConnection(connetionString)
    oledbCnn1.Open()
    oledbCmd1 = New OleDbCommand(sql, oledbCnn1)
    Dim oledbReader1 As OleDbDataReader = oledbCmd1.ExecuteReader()
    While oledbReader1.Read
	    cod_mod = oledbReader1.Item(0)
    End While
    oledbReader1.Close()
    oledbCmd1.Dispose()
    oledbCnn1.Close()
    'MsgBox(cod_mod)
    For Each item As DataGridViewRow In DataGridView1.Rows

	    'MsgBox(item.Cells(0).Value)
	    'MsgBox(item.Cells(1).Value)
	    'MsgBox(item.Cells(2).Value)
	    'MsgBox(item.Cells(3).Value)
	    Dim aa As String = item.Cells(3).Value
	    Dim oledbCnn2 As OleDbConnection
	    Dim oledbCmd2 As OleDbCommand
	    Dim processo As Integer
	    Dim Sql1 As String = "Select n_processo from aluno where nome= '" & aa & "'"
	    oledbCnn2 = New OleDbConnection(connetionString)
	    Try
		    oledbCnn2.Open()
		    oledbCmd2 = New OleDbCommand(Sql1, oledbCnn2)
		    Dim oledbReader2 As OleDbDataReader = oledbCmd2.ExecuteReader()
		    While oledbReader2.Read
			    processo = oledbReader2.Item(0)
			    'MsgBox(processo)
		    End While
	    Finally
	    End Try
	    Dim bb As String = item.Cells(0).Value
	    bb = Format(item.Cells(0).Value, "dd-MM-yyyy") '& "%"
	    'MsgBox(bb)
	    Dim cc As String = item.Cells(1).Value
	    'MsgBox(cc)
	    Dim dd As String = item.Cells(2).Value
	    'MsgBox(dd)
	    Dim sql3 As String = "Insert Into classificacao_modulo ([id_modulo], [classificacao], [classificacao_extenso], [n_processo], [data_conclusao]) values (" & cod_mod & "," & cc & ",'" & dd & "'," & processo & ",'" & bb & "')"
	    Dim cmd1 As New OleDbCommand(sql3, mydb)
	    cmd1.ExecuteNonQuery()
	    MsgBox("Avaliações introduzidas!")

Ele insere o dados mas depois dá-me o seguinte erro:

Erro de sintaxe na instrução INSERT INTO.

Na linha:

cmd1.ExecuteNonQuery()

Do seguinte bocado de código:

Dim sql3 As String = "Insert Into classificacao_modulo ([id_modulo], [classificacao], [classificacao_extenso], [n_processo], [data_conclusao]) values (" & cod_mod & "," & cc & ",'" & dd & "'," & processo & ",'" & bb & "')"
	    Dim cmd1 As New OleDbCommand(sql3, mydb)
	    cmd1.ExecuteNonQuery()
	    MsgBox("Avaliações introduzidas!")
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.