Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Searched The Whole Internet For This ACCESS DATABASE And VB.NET Connect ERROR!!

[Image: 31vSJ.png]

Source :

PHP Code

<?php 
Dim database 
As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & System.Environment.CurrentDirectory & "\test.accdb")
  
Dim cmdadd As New OleDb.OleDbCommand
  cmdadd
.CommandText = "INSERT INTO table (ID, name) VALUES (@ID, @name);"
  
cmdadd.Connection = database
  cmdadd
.Parameters.AddWithValue("ID", txtid.Text)
  
cmdadd.Parameters.AddWithValue("name", txtname.Text)
  
database.Open()
  
cmdadd.ExecuteNonQuery()
  
database.Close() 

and Tested This :

PHP Code

<?php 
If Me.txtidsamad.Tag & "" = "" Then
    
'add new 
    '
add data to table
    cmd
.CommandText = "INSERT INTO table([iD], [name]) VALUES (" & Me.txtid.Text & "," & Me.txtname.Text & ")"
    
cmd.ExecuteReader()
    
cnn.Close()
    
MsgBox("Added Successfully")
    Else
    
msgbox(ex.message)
    
End If

  
End If 

Working on Access Database (Office 2007)

[Image: 31vXq.png]

Any Help ?
asked Friends in HF and google, Yahoo, Bing And everything!!

Thanks in advance.
"Insert Into db (name, id) Values('a', '1')"
Yeah, try putting single quotes before/after the double quotes before your variables. Like this:

cmd.CommandText = "INSERT INTO table([iD], [name]) VALUES ('" & Me.txtid.Text & "','" & Me.txtname.Text & "')"
(May 26, 2013 08:15 AM)Cody8295 Wrote:  Yeah, try putting single quotes before/after the double quotes before your variables. Like this:

cmd.CommandText = "INSERT INTO table([iD], [name]) VALUES ('" & Me.txtid.Text & "','" & Me.txtname.Text & "')"

No that's a very bad habit. Just use parameters for inserting variables.
(May 26, 2013 07:15 AM)C3ol Wrote:  "Insert Into db (name, id) Values('a', '1')"

Got the Same Error another solution ?..
Thanks in advance


(May 26, 2013 08:15 AM)Cody8295 Wrote:  Yeah, try putting single quotes before/after the double quotes before your variables. Like this:

cmd.CommandText = "INSERT INTO table([iD], [name]) VALUES ('" & Me.txtid.Text & "','" & Me.txtname.Text & "')"

ExecuteNonQuery Error Same Error ..
Thanks For Helping anyways..🤨


(May 26, 2013 08:27 AM)x64 Wrote:  No that's a very bad habit. Just use parameters for inserting variables.

Hey man can you help me with that..?
Thank you
(May 26, 2013 08:49 AM)scoder Wrote:  Got the Same Error another solution ?..
Thanks in advance



ExecuteNonQuery Error Same Error ..
Thanks For Helping anyways..🤨

When using parameters you're a supposed to replace the word you've added.

So not :

Code
cmdadd.Parameters.AddWithValue("ID", txtid.Text)
  cmdadd.Parameters.AddWithValue("name", txtname.Text)

But

Code
cmdadd.Parameters.AddWithValue("@ID", txtid.Text)
  cmdadd.Parameters.AddWithValue("@name", txtname.Text)
(May 26, 2013 08:52 AM)x64 Wrote:  When using parameters you're a supposed to replace the word you've added.

So not :

Code
cmdadd.Parameters.AddWithValue("ID", txtid.Text)
  cmdadd.Parameters.AddWithValue("name", txtname.Text)

But

Code
cmdadd.Parameters.AddWithValue("@ID", txtid.Text)
  cmdadd.Parameters.AddWithValue("@name", txtname.Text)
So the Code Will Be Like This :
PHP Code

<?php 
Dim database 
As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & System.Environment.CurrentDirectory & "\test.accdb")
  
Dim cmdadd As New OleDb.OleDbCommand
  cmdadd
.CommandText = "INSERT INTO table (ID, name) VALUES (@ID, @name);"
  
cmdadd.Connection = database
  cmdadd
.Parameters.AddWithValue("@ID", txtid.Text)
  
cmdadd.Parameters.AddWithValue("@name", txtname.Text)
  
database.Open()
  
cmdadd.ExecuteNonQuery()
  
database.Close() 

But Still Getting The Same Error.. :/
(May 26, 2013 08:27 AM)x64 Wrote:  No that's a very bad habit. Just use parameters for inserting variables.

... This isn't PHP, you can't do it like that.
(May 26, 2013 09:53 AM)Cody8295 Wrote:  ... This isn't PHP, you can't do it like that.

I know it's not PHP. When using queries in ODB, you can use parameters for data. Look at my previous post
It's injection safe.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Avispon99Sep 18, 2019 10:56 PM 1 81 Sep 18, 2019 10:56 PM
Last Post: magicparty
[.NET] by UijaJul 22, 2018 06:01 AM 2 140 Jul 22, 2018 06:01 AM
Last Post: Uija
[Java] by pampos1Mar 12, 2018 01:37 PM 2 90 Mar 12, 2018 01:37 PM
Last Post: pampos1