mariogx Posted May 17, 2006 at 11:24 AM Report Share #27812 Posted May 17, 2006 at 11:24 AM Boas!!!! Tou k problemas a inserir dados na base de dados a partir du vb 2005... o erro encontra-se no comando executenonquery.. o erro é o seguinte: ExecuteNonQuery: Connection property has not been initialized. o código é este: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'inserir dados Dim valor As Integer ligação.Open() 'abrir a ligação Dim sql As New OleDbCommand("insert into doc(ID,Nome,Gabinete,Extensão,Telefone,DS,User,Pass) values('" & txtid.Text & "','" & txtnome.Text & "','" & txtgab.Text & "','" & txtex.Text & "','" & txttel.Text & "','" & combods.SelectedValue & "','" & txtuser.Text & "','" & txtpass.Text & "'") valor = sql.ExecuteNonQuery() ligação.Close() 'fechar a ligação End Sub HELP ME!!! Link to comment Share on other sites More sharing options...
RicardoBastos Posted May 22, 2009 at 03:35 PM Report Share #266530 Posted May 22, 2009 at 03:35 PM Dim sql As New OleDbCommand sql = ("insert into doc(ID,Nome,Gabinete,Extensão,Telefone,DS,User,Pass) values('" & txtid.Text & "','" & txtnome.Text & "','" & txtgab.Text & "','" & txtex.Text & "','" & txttel.Text & "','" & combods.SelectedValue & "','" & txtuser.Text & "','" & txtpass.Text & "'") dataAdapter.InsertCommand = New OleDb.OleDbCommand(sql, ligacao) ligacao.Open() dataAdapter.InsertCommand.ExecuteNonQuery() ligacao.Close() Mas antes de tentar isto altera os caracteres especias como "ç" ou "ã" nota : dataAdapter é uma variavel do tipo dataAdapter Cumps Link to comment Share on other sites More sharing options...
devin Posted May 25, 2009 at 03:50 PM Report Share #267137 Posted May 25, 2009 at 03:50 PM tinha também esse problema e foi assim que resolvi. Dim sql As New OleDbCommand sql = ("insert into doc(ID,Nome,Gabinete,Extensão,Telefone,DS,User,Pass) values('" & txtid.Text & "','" & txtnome.Text & "','" & txtgab.Text & "','" & txtex.Text & "','" & txttel.Text & "','" & combods.SelectedValue & "','" & txtuser.Text & "','" & txtpass.Text & "'") dataAdapter.InsertCommand = New OleDb.OleDbCommand(sql, ligacao) ligacao.Open() dataAdapter.InsertCommand.Connection=ligacao dataAdapter.InsertCommand.ExecuteNonQuery() ligacao.Close() Link to comment Share on other sites More sharing options...
vasco16 Posted May 25, 2009 at 03:54 PM Report Share #267140 Posted May 25, 2009 at 03:54 PM não é mais facil usar parametros do que inserir tudo logo de uma vez ?:S Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now