1 Replies - 15300 Views - Last Post: 26 March 2008 - 07:55 AM Rate Topic: -----

#1 CJ Revo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-March 08

Write data to a database

Posted 26 March 2008 - 03:01 AM

I'm currently attempting to set up a login for my program. I've got a seperate form which I will need to allow users to create a new profile by adding their "Name", "Age" and "gender". Then I have a seperate button on the form which I need to write the information to the corresponding table I have called "users" in my access database. I've written the base code, i.e. making the database connections but I'm not entirely sure how i'm supposed to write the code for actually sending the information off to the database.

My code...

Public Class frmNewUser
	Public objReader As System.Data.OleDb.OleDbDataReader
	Public objWriter As System.Data.OleDb.OleDbDataAdapter

	Private Const conn As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
	"Data Source=london_aquarium.accdb;Persist Security Info =False;"

	Private objConnection As New System.Data.OleDb.OleDbConnection(conn)
	Private strSQL As String = "INSERT INTO users (Name, age, gender) VALUES"

	Private objDataAdapter As New OleDb.OleDbDataAdapter(strSQL, conn)
	Private objDataSet As New DataSet
	Private objTable As New DataTable
	Private objRow As DataRow


	Private Sub frmNewUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		objConnection.Open()
		objDataAdapter.Fill(objDataSet, "Users")
		objTable = objDataSet.Tables("Users")
		objConnection.Close()
		objConnection.Dispose()

	End Sub

	Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
		Dim name As String
		Dim age As Integer

		name = txtName.Text
		age = txtAge.Text

		MsgBox("Your settings have been saved")
		loginForm.Show()
		Me.Hide()
	End Sub
End Class


would be very appreciated if anyone could help. thanks

This post has been edited by CJ Revo: 26 March 2008 - 03:10 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Write data to a database

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Write data to a database

Posted 26 March 2008 - 07:55 AM

First off this is VB.Net so I will be moving this to the VB.NET Forum. Secondly, read this tutorial on OleDb Data Objects in VB.Net, that will give you the answers you need :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1