|
-
May 31st, 2007, 02:11 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Simple CODE
I am current still learning in database, and i figure some of this hard to code.
This is how i add a record in a access using VB6.0
Code:
Call Opening
ObjRS.Open "Contact", ObjConn, adLockOptimistic, adOpenStatic, adCmdTable
ObjRs.AddNew
ObjRs.Fileds("Sname") = txtName.Text
ObjRs.Fields("Number") = txtNumber.Text
ObjRs.Fields("Address") = txtAddress.Text
ObjRs.Update
MsgBox ("Record Added")
Call Closing
its very simple but when im using VB.Net using this code
Code:
Option Strict On
Option Explicit On
Imports System.Windows.Forms.Form
Imports System.Data.OleDb
Public Class CreateAccount
Private contactID As Int64 = 0
Public Property Contact() As Int64 '
Get
Return contactID
End Get
Set(ByVal value As Int64)
contactID = value
End Set
End Property
Public Sub RetriveRecords()
Dim ObjConn As New OleDbConnection("Provider = Microsoft.Jet.OleDb.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\DBase\Bank.mdb;")
Dim dAdapter As New OleDbDataAdapter("SELECT * FROM UserDatabase", ObjConn)
Dim dTable As New DataTable
dAdapter.Fill(dTable)
Database.AccessDatabase.DataSource = dTable
End Sub
Private Sub btnSave_CLick(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
Dim ObjConn As New OleDbConnection("Provider = Microsoft.Jet.OleDb.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\DBase\Bank.mdb;")
Dim sql As String = String.Empty
If contactID = 0 Then
sql = "INSERT INTO UserDatabase(Ename,Address,ContactNumber,AmountPaid,DatePaid,PeriodTime)" _
& "VALUES('" & txtEname.Text & "','" & txtAddress.Text & "','" & txtContact.Text & "','" & txtAmount.Text & "','" & txtDate.Text & "','" & cboPeriod.Text & "')"
End If
ObjConn.Open()
Dim dCMd As New OleDbCommand(sql, ObjConn)
dCMd.ExecuteNonQuery()
ObjConn.Close()
MessageBox.Show("Record Added")
I use the Public Property to determine what im going to do. Is there any simple code reather than that. As simple in VB6.0
-
May 31st, 2007, 02:25 AM
#2
Re: [2005] Simple CODE
Thanks for providing that VB6 code, although it's completely useless because this is VB.NET and you're using ADO.NET.
http://www.vbforums.com/showthread.php?t=469872
-
May 31st, 2007, 02:33 AM
#3
Thread Starter
Fanatic Member
Re: [2005] Simple CODE
Thank you for the link, but is it more appropriate to use the SQL namespace instead using the oledb namespace ?
-
May 31st, 2007, 02:38 AM
#4
Re: [2005] Simple CODE
Read that thread properly and you'll have your answer. It's in the very first paragraph.
-
May 31st, 2007, 02:40 AM
#5
Fanatic Member
Re: [2005] Simple CODE
it depends oon the kind of database you want to use. if Access best suits your need, you use the oledb otherwise, you go for sql. jmc used sql because that what he was using for his example.
-
May 31st, 2007, 02:43 AM
#6
Thread Starter
Fanatic Member
Re: [2005] Simple CODE
Yah your right i get the answer, if i use the SQL namespace i can write less code, all the SQL statements are added in a Dataset, and im going to do is just call the methods.
-
May 31st, 2007, 02:46 AM
#7
Re: [2005] Simple CODE
 Originally Posted by Loraine
Yah your right i get the answer, if i use the SQL namespace i can write less code, all the SQL statements are added in a Dataset, and im going to do is just call the methods.
No, that's not it.
 Originally Posted by jmcilhinney
This code uses members of the System.Data.SqlClient namespace. If you're not using SQL Server then it's a simple matter of switching to the corresponding types of the appropriate namespace for your data source.
SqlClient is, as its documentation says, for use with SQL Server. If you're using an OLEDB provider, like Jet with Access, then you use OleDb.
-
May 31st, 2007, 02:51 AM
#8
Thread Starter
Fanatic Member
Re: [2005] Simple CODE
Yah i know that, im just saying that if i use the SQLClient i can write less code and just call all the methods of SQL statements that are stored in a Dataset.
-
May 31st, 2007, 02:56 AM
#9
Fanatic Member
Re: [2005] Simple CODE
that will be exactly the same if you use oledb and dataset. You will ahve to write the same amount of code
-
May 31st, 2007, 02:56 AM
#10
Re: [2005] Simple CODE
 Originally Posted by Loraine
Yah i know that, im just saying that if i use the SQLClient i can write less code and just call all the methods of SQL statements that are stored in a Dataset.
No, that doesn't have anything to do with anything I'm afraid. In VS 2005 you can create a typed DataSet with accompnying TableAdapters for basically any data source. If you do that you will be writing less code and you will not be using SqlClient, OleDb or any other provider directly. The IDE will generate most of the code for you, but under the hood it will still use SqlClient for SQL Server and OleDb for Access.
-
May 31st, 2007, 02:59 AM
#11
Thread Starter
Fanatic Member
Re: [2005] Simple CODE
Thank you jmcillhiney and talkro, well im translating the code of jmc use in SQLClient into an oledb.
-
May 31st, 2007, 03:18 AM
#12
Thread Starter
Fanatic Member
Re: [2005] Simple CODE
Before im going to Resolved this thread, im trying to use the ManageData but i cant find it in a library ?
-
May 31st, 2007, 04:00 AM
#13
Re: [2005] Simple CODE
 Originally Posted by Loraine
Before im going to Resolved this thread, im trying to use the ManageData but i cant find it in a library ?
I have no idea what you mean. Is this related to the previous question?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|