Jump to content

Recommended Posts

Posted (edited)

O código é este:


	Dim connetionString As String
	Dim oledbCnn As OleDbConnection
	Dim oledbCmd As OleDbCommand
	Dim oledbCmd1 As OleDbCommand
	Dim cod_cur, cod_tur As Integer

	connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\GPSI\Documents\mydb.accdb;"
	Dim nome_disciplina = ComboBox3.SelectedItem
	Dim mydb As New OleDbConnection(connetionString)
	mydb.Open()
	Dim a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, x, z, aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll, mm, nn, oo, pp, qq, rr, ss, tt, uu, vv, aaa, bbb, ccc, eee, fff As String
	Dim sql, sql1, sql2, sql3, sql4 As String
	a = txtprocesso.Text
	b = txtnomealuno1.Text
	c = combosexo.Text
	d = Format(datatimenascialuno.Value, "dd-MM-yyyy")
	f = txtnacialuno.Text
	g = txtnomealuno2.Text
	h = txtemailaluno.Text
	i = txtmoradaluno.Text
	j = txtcodpostaluno1.Text
	k = txtcodpostaluno2.Text
	l = txtlocalidadealuo.Text
	m = txtconcnataluno.Text
	n = txtfregnataluno.Text
	o = txtpaisnataluno.Text
	p = txtdistriresialuno.Text
	q = txtconcresialuno.Text
	r = txtfregresialuno.Text
	s = combofami.Text
	t = txtmedicoaluno.Text
	u = Format(datatimevacina.Value, "dd-MM-yyyy")
	v = txtocorraluno.Text
	x = txtanotaluno.Text
	z = txtnomepai.Text
	aa = txtprofpai.Text
	bb = txtnomemae.Text
	cc = txtprofmae.Text
	dd = txttelepai.Text
	ee = txttelemae.Text
	ff = txtnatupai.Text
	gg = txtnatumae.Text
	hh = comboemppai.Text
	ii = comboempmae.Text
	jj = comboformpai.Text
	kk = comboformmae.Text
	ll = txtnomeEE.Text
	mm = txtmoradaEE.Text
	nn = txtcodpostEE1.Text
	oo = txtcodpostEE2.Text
	pp = txtlocaliEE.Text
	qq = ComboBox1.Text
	rr = txtteleEE.Text
	ss = txtnatEE.Text
	tt = txtprofEE.Text
	uu = comboempEE.Text
	vv = ComboBox2.Text
	aaa = txtbi.Text
	bbb = Format(databi.Value, "dd-MM-yyyy")
	ccc = TextBox3.Text
	eee = TextBox4.Text
	fff = TextBox2.Text

	sql1 = "select cod_curso from curso where nome ='" & ComboBox3.Text & "'"
	oledbCnn = New OleDbConnection(connetionString)
	Try
		oledbCnn.Open()
		oledbCmd = New OleDbCommand(sql1, oledbCnn)
		Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader()
		While oledbReader.Read
			cod_cur = oledbReader.Item(0)
			MsgBox(cod_cur)
		End While
	Finally
	End Try
	sql2 = "select cod_turma from turma where ano=10 and cod_curso like '%" & cod_cur & "%'"
	oledbCnn = New OleDbConnection(connetionString)
	Try
		oledbCnn.Open()
		oledbCmd1 = New OleDbCommand(sql2, oledbCnn)
		Dim oledbReader1 As OleDbDataReader = oledbCmd1.ExecuteReader()
		While oledbReader1.Read
			cod_tur = oledbReader1.Item(0)
			MsgBox(cod_tur)
		End While
	Finally
	End Try
	'''''''''''''''''''''
	sql3 = "Insert Into encarregado_educacao ([nome_ee], [telefone_ee], [morada_ee], [profissao_ee], [escolaridade_ee], [naturalidade_ee], [empego_ee], [cod_postal_ee1], [cod_postal_ee2], [localidade_ee], [parentesco_ee]) values ('" & ll & "','" & rr & "','" & mm & "','" & tt & "','" & vv & "','" & ss & "','" & uu & "', '" & nn & "','" & oo & "','" & pp & "','" & qq & "')"
		Dim cmd1 As New OleDbCommand(sql3, mydb)
		cmd1.ExecuteNonQuery()

	''''''''''

	Dim oledbCmda As OleDbCommand
	Dim sqla As String
	Dim cod_eee As Integer
	sqla = "SELECT Max (encarregado_educacao.cod_ee) FROM encarregado_educacao;"
	oledbCnn = New OleDbConnection(connetionString)
	oledbCnn.Open()
	oledbCmda = New OleDbCommand(sqla, oledbCnn)
	Dim oledbReadera As OleDbDataReader = oledbCmda.ExecuteReader()
	While oledbReadera.Read
		cod_eee = oledbReadera.Item(0) + 1
	End While
	MsgBox(cod_eee)

	'''''''''''''''''''''''''''''''

		sql4 = "Insert Into filiacao ([nome_pai], [nome_mae], [profissao_pai], [profissao_mae], [naturalidade_pai], [naturalidade_mae], [emprego_pai], [emprego_mae], [estudos_pai], [estudos_mae], [telefone_pai], [telefone_mae]) values ('" & z & "','" & bb & "','" & aa & "','" & cc & "', '" & ff & "','" & gg & "','" & hh & "','" & ii & "','" & jj & "','" & kk & "','" & dd & "','" & ee & "' )"
		Dim cmd2 As New OleDbCommand(sql4, mydb)
		cmd2.ExecuteNonQuery()

	''''''''''

	Dim oledbCmdb As OleDbCommand
	Dim sqlb As String
	Dim cod_fil As Integer
	sqlb = "SELECT Max (filiacao.cod_filiacao) FROM filiacao;"
	oledbCnn = New OleDbConnection(connetionString)
	oledbCnn.Open()
	oledbCmdb = New OleDbCommand(sqlb, oledbCnn)
	Dim oledbReaderb As OleDbDataReader = oledbCmdb.ExecuteReader()
	While oledbReaderb.Read
		cod_fil = oledbReaderb.Item(0) + 1
	End While
	MsgBox(cod_fil)

	'''''''''''''''''''''''''''''''

	sql = "Insert Into aluno  ([nome], [sexo], [data_nascimento], [bi], [validade_bi], [anotacoes], [morada], [cod_postal1], [cod_postal2], [telemovel], [ocorrencia], [n_medico], [vacinas], [n_ssocial], [nif], [agreg_familiar], [localidade], [email], [natufreguesia], [natuconcelho], [natupais],  [residistrito], [resiconcelho], [resifreguesia], [cod_turma], [cod_ee], [cod_filiacao]) values ('" & b & "','" & c & "','" & d & "','" & aaa & "','" & bbb & "','" & x & "', '" & i & "','" & j & "','" & k & "', '" & fff & "','" & v & "', '" & t & "', '" & u & "', '" & ccc & "', '" & eee & "', '" & s & "', '" & l & "', '" & h & "', '" & n & "', '" & m & "','" & o & "', '" & p & "', '" & q & "', '" & r & "', '" & cod_tur & "', '" & cod_eee & "', '" & cod_fil & "')"
		Dim cmd As New OleDbCommand(sql, mydb)
		cmd.ExecuteNonQuery()
	MsgBox("Aluno Introduzido!")
End Sub
Edited by Caça
GeSHi
Posted (edited)

Neste cmd:

cmd1.ExecuteNonQuery()

Diz capacidade excedida!

sql3 = "Insert Into encarregado_educacao ([nome_ee], [telefone_ee], [morada_ee], [profissao_ee], [escolaridade_ee], [naturalidade_ee], [empego_ee], [cod_postal_ee1], [cod_postal_ee2], [localidade_ee], [parentesco_ee]) values ('" & ll & "','" & rr & "','" & mm & "','" & tt & "','" & vv & "','" & ss & "','" & uu & "', '" & nn & "','" & oo & "','" & pp & "','" & qq & "')"
					Dim cmd1 As New OleDbCommand(sql3, mydb)
				   cmd1.ExecuteNonQuery()
Edited by jpaulino
Bloco código

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
×
×
  • 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.