4 Replies - 4460 Views - Last Post: 11 March 2009 - 02:02 PM Rate Topic: -----

#1 Black_Widow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 01-February 09

Insertion of Data into Access DB using vb.net 2008

Posted 10 March 2009 - 12:38 PM

I'm getting this error when I go to insert data into access DB using vb.net 2008 which is specified by the user.

"OleDbException was Unhandled
No value given for one or more required parameters "

If I hard code the values it works just fine.
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
	Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Database\Database1.accdb")



	Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim cmd As New OleDbCommand("Insert into Table1 Values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')", conn)
		conn.Open()
		cmd.ExecuteNonQuery()
		MsgBox("Successfully Record Saved.....!", MsgBoxStyle.Information)
		conn.Close()
	End Sub
End Class



Really need this urgently.
Thanking in advance....

Is This A Good Question/Topic? 0
  • +

Replies To: Insertion of Data into Access DB using vb.net 2008

#2 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 51
  • View blog
  • Posts: 1,179
  • Joined: 05-June 08

Re: Insertion of Data into Access DB using vb.net 2008

Posted 10 March 2009 - 01:27 PM

what are the values in the text box?

And try using a Try Catch block for the error messages

This post has been edited by Damage: 10 March 2009 - 01:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 Black_Widow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 01-February 09

Re: Insertion of Data into Access DB using vb.net 2008

Posted 10 March 2009 - 01:35 PM

View PostDamage, on 10 Mar, 2009 - 12:27 PM, said:

what are the values in the text box?

And try using a Try Catch block for the error messages



in the textbox I'm inserting string values.
but still it's givin an error.
in the form there r 6 textboxes...and 1 button

This post has been edited by Black_Widow: 10 March 2009 - 01:36 PM

Was This Post Helpful? 0
  • +
  • -

#4 greywolv2006  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 13-January 09

Re: Insertion of Data into Access DB using vb.net 2008

Posted 11 March 2009 - 04:16 AM

you should not insert string when declaring cmd.
you should build the string before declaring cmd, such as ;

dim insertsql as string="INSERT INTO table1 (field1, field2,field3) VALUES (@text1,@text2,@text3)"
dim cmd as oledbcommand=new oledbcommand(insertsql,conn)
cmd.Parameters.AddWithValue("@text1",Textbox1.text)
cmd.Parameters.AddWithValue("@text2",Textbox2.text)
cmd.Parameters.AddWithValue("@text3",Textbox3.text)
dim rowsaffected as integer=cmd.executenonquery
messagebox.show(rowsaffected.tostring & " row added")



what you'll be doing here is telling cmd to replace '@text1,text2 & text3' with values in textboxes...much more secure and simpler.

tell me if it works
Was This Post Helpful? 1
  • +
  • -

#5 Black_Widow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 01-February 09

Re: Insertion of Data into Access DB using vb.net 2008

Posted 11 March 2009 - 02:02 PM

Hey Thanks a millions it worked just fine...... :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1