Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old April 10th, 2008, 03:56 PM
sonia.sardana sonia.sardana is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 10 sonia.sardana User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
DataBase Connectivity-VB + SQL

Can Somebody send me the coding database Connectivity of VB With SQL. Cz I m new to the VB.

Reply With Quote
  #2  
Old April 11th, 2008, 03:01 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,025 sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 4 h 38 m 59 sec
Reputation Power: 608
Hi,

You haven't provided a lot of information - exactly what version of VB are you using? VB6? You say SQL, I assume you mean SQL Server, what version? etc.. The more information you provide the better the response you will get.

Heres a quick demonstration of using VB6 to set up an ADODB connection with a SQL Server DB. Note, you must first add a reference to the relevant library, go to Project -> References, scroll down to "Microsoft ActiveX Data Objects 2.x Library" (where x is the highest number in the list), put a tick in the box and click "OK". You can now declare and use an ADODB connection to your DB:
Code:
'First declare variables to hold details of your connection and recordset - which will hold any records returned
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

'Establish a connection to your DB - you can find the correct connection string at www.connectionstrings.com
cn.Open "Provider=MSDataShape;DRIVER={SQL SERVER};Server=yourserver;Database=yourdatabase;UI  D=youruser;PWD=yourpassword;"

'You can now query the database connection and store any records returned in your recordset
'Define string variable to hold SQL statement
Dim strSQL As String

'Construct SQL String
strSQL = "set dateformat dmy; select * from mytable order by myfield asc"

'Execute the SQL Statement
Set rs = cn.Execute(strSQL)

'You can now test to see if the sql statement returned rows, if it did you can loop through the recordset displaying the details
If rs.EOF <> True And rs.BOF <> True Then
    While Not rs.EOF
        
        'Print the contents of the first field of the current record
        Debug.Print rs.Fields(0)

	'Move to the next record
	rs.MoveNext
    Wend
Else
	MsgBox "No records returned"
End If

'Dont forget to close your recordset/connection
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

This is just a basic demonstration, you will find tons of information on the Net to help you get started. If you get stuck please post a detailed description of your problem, along with any code you have, and we will try and point you in the right direction.

Reply With Quote
  #3  
Old April 11th, 2008, 03:53 PM
sonia.sardana sonia.sardana is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 10 sonia.sardana User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
VB Version is 6.o & SQL Version is 2000.

Database Table-
create table stuinfo(roll int,name varchar(10),marks int)
select * from stuinfo

Till Now, I have currently did as below-
Private Sub Form_Load()
Dim gcn As New ADODB.Connection
gcn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=sonia"
Dim query As String
query = "Insert into stuinfo values("
End Sub

I want to just insert the records into the database.

Reply With Quote
  #4  
Old April 14th, 2008, 03:28 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,025 sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 4 h 38 m 59 sec
Reputation Power: 608
Quote:
Originally Posted by sonia.sardana
I want to just insert the records into the database.

I'm afraid I dont understand what you are asking, are you getting an error?

Possible problems you may face are:

You are only defining the field "name" as up to ten characters, is this really enough to store a name?

Secondly, at least one of your field names is a reserved word (name), you will need to surround them with square brackets so SQL Server will know to treat them as field names.

Finally, you dont appear to be opening the connection, use the .Open command.

Heres an example which you should be able to adapt.
Code:
Private Sub Form_Load()
Dim gcn As New ADODB.Connection, query As String
gcn.Open = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=sonia"

Dim intRoll, intMarks As Integer
Dim strName As String

intRoll = 12
intMarks = 80
strName = "Sync_or_Swim" 

query = "Insert into stuinfo([roll], [name], [marks]) " & _
"values(" & intRoll & ", '" & strName & "', " & intMarks & ")"
gcn.Execute(query)

gcn.Close
Set gcn = Nothing

End Sub

Reply With Quote
  #5  
Old April 14th, 2008, 12:29 PM
sonia.sardana sonia.sardana is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 10 sonia.sardana User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
Private Sub Form_Load()
Dim gcn As New ADODB.Connection
gcn.Open = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=sonia"
Dim query As String


query = "Insert into stuinfo values([roll],[name],[marks]), &_"
values("& me.txtroll.Text &","& me.txtname.Text &","&me.txtmarks.Text &")
gcn.Execute (query)
MsgBox "Record Inserted"
gcn.Close
End Sub

I have tried this code,but errors are there,Plz help to find out where are they??

Reply With Quote
  #6  
Old April 15th, 2008, 05:55 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,025 sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 4 h 38 m 59 sec
Reputation Power: 608
Quote:
Originally Posted by sonia.sardana
I have tried this code,but errors are there,Plz help to find out where are they??

What errors are there???? The more information you give me the more I can help!!!

There are several factors that might cause errors, it may be that there is a problem accessing the database, or it could be that you have a syntax error in your SQL statement.

At a glance, it appears that you have mis-typed the code I posted, you have to be careful that you write things in the correct order. Here is the code you posted:
Code:
Private Sub Form_Load()
Dim gcn As New ADODB.Connection
gcn.Open = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=sonia"
Dim query As String

query = "Insert into stuinfo values([roll],[name],[marks]), &_"
values("& me.txtroll.Text &","& me.txtname.Text &","&me.txtmarks.Text &")
gcn.Execute (query)
MsgBox "Record Inserted"
gcn.Close
End Sub

If you focus on the sql query: your continuation character on the end of the first line should be outside of the quotes, and there should be a double quote on the end of the string. Also, the column definitions should be before the values. Try copying this VERBATIM:
Code:
Private Sub Form_Load()
Dim gcn As New ADODB.Connection, query As String
gcn.Open = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=sonia"

query = "Insert into stuinfo ([roll],[name],[marks]) " & _
"values("& me.txtroll.Text & ", " & me.txtname.Text & ", " & me.txtmarks.Text & " )"

gcn.Execute (query)
MsgBox "Record Inserted"
gcn.Close
End Sub

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > DataBase Connectivity-VB + SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway