Connect SQL using VB.Net


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 3 123 LastLast
Results 1 to 15 of 33

Thread: Connect SQL using VB.Net

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    843

    Connect SQL using VB.Net

    Hello all expert VB.Net programmer, i need to connect to sql server using VB.Net but i don't know and i also try look into some tutorial but also not very understand.

    I hope you all can guide me.

    A sample of program and little explanation is greatly appreciated by me and others readers as well.

    A billion thanks for your help.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Here is another good resource.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    May 2007
    Posts
    843
    I will have a look the resource first and come back with a specific question.

    A billion thanks for your help.

  5. #5
    Join Date
    May 2007
    Posts
    843
    I try to browse through those website and i not understand about the connection string.

    How can i find out my SQL server apth ?

    Can u provide some basic code which connect to SQL ?

    A billion thanks for all your help.

  6. #6
    Join Date
    May 2007
    Posts
    843
    VB\AdoOverView1.vb Font Size:
    C# Source: CS\AdoOverView1.cs CS\AdoOverView1.aspx
    VB Source: VB\AdoOverView1.vb VB\AdoOverView1.aspx
    VJ# Source: VJS\AdoOverView1.jsl VJS\AdoOverView1.aspx
    C++ Source: CP\AdoOverView1.cpp

    Imports System
    Imports System.Data.SqlClient

    namespace HowTo.Samples.ADONET

    public class adooverview1
    public shared sub Main()
    Dim myadooverview1 as adooverview1
    myadooverview1 = new adooverview1()
    myadooverview1.Run()
    end sub

    public sub Run()
    Dim mySqlConnection as SqlConnection

    mySqlConnection = new SqlConnection("server=(local)\NetSDK;Trusted_Connection=yes;database=northwind")

    try
    mySqlConnection.Open()
    Console.WriteLine("Opened Connection to {0}", mySqlConnection.ConnectionString)

    ' Close the connection explicitly
    mySqlConnection.Close()
    Console.WriteLine("Closed Connection. It is important to close connections explicitly.")
    catch
    Console.WriteLine("Couldn't Open Connection to {0}", mySqlConnection.ConnectionString)
    end try
    end sub
    end class

    end namespace


    http://samples.gotdotnet.com/quickst...soverview.aspx

    How to create a database before connect to MS SQL server ?

    I really need help.

  7. #7
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by Peter_APIIT
    How to create a database before connect to MS SQL server ?
    If you have the SQL Server software installed, there are built in tools to build your database.

    As far as connecting is concerned, take a look at http://www.connectionstrings.com/
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  8. #8
    Join Date
    May 2007
    Posts
    843
    I using MS SQL server 2005. What built in tool to create a databse and table in MS SQL server 2005 ?

    I only have configuration manager, Error and Usage reporting and surface area configuration.

    A billion thanks for oyur help

  9. #9
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  10. #10
    Join Date
    May 2007
    Posts
    843
    I found htis website

    http://<br /> http://technet.micros...hot.aspx<br />

    Good for beginner.
    Last edited by Peter_APIIT; 02-24-2008 at 10:08 PM.

  11. #11
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    So, is your question answered or do you still have issues?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  12. #12
    Join Date
    May 2007
    Posts
    843
    Thanks for your concern. I have try as follow:

    Imports System
    Imports System.Data.SqlClient



    Public Class Admin_Login

    Private Sub Admin_Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim mysqlconnection As SqlConnection
    Dim mysqlcommand As SqlCommand
    Dim mysqlreaqder As SqlDataReader

    'Dim mysqlconnectionDataAdapter As SqlDataAdapter

    mysqlconnection = New SqlConnection("server=localhost;Trusted_Connection=yes;database=VCD")


    If mysqlconnection.State = ConnectionState.Closed Then
    Try
    mysqlconnection.Open()

    mysqlcommand = New SqlCommand("select * from VCD")

    mysqlreaqder = mysqlcommand.ExecuteReader()

    While mysqlreaqder.Read
    MessageBox.Show("xfallback_dbid")

    End While


    Catch ex As Exception

    End Try

    If mysqlconnection.State = ConnectionState.Connecting Then
    mysqlconnection.Close()
    End If
    Else
    Me.Close()
    End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Me.Close()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    Dim userName As String

    userName = TextBox1.Text

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
    Dim password As String

    password = TextBox2.Text

    End Sub
    End Class
    Besides this, i also try another code but cannot insert into the databse.

    Imports System
    Imports System.Data.SqlClient



    Public Class Admin_Login

    Private Sub Admin_Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim mysqlconnection As SqlConnection
    Dim myfirstsqlcommand As SqlCommand
    Dim mysecondsqlcommand As SqlCommand

    Dim mysqlreaqder As SqlDataReader

    'Dim mysqlconnectionDataAdapter As SqlDataAdapter

    mysqlconnection = New SqlConnection("server=localhost;Trusted_Connection=yes;database=VCD")


    If mysqlconnection.State = ConnectionState.Closed Then
    Try
    mysqlconnection.Open()

    myfirstsqlcommand = New SqlCommand("Insert into Admin Table values peter, 1234, _mysqlconnection")

    mysecondsqlcommand = New SqlCommand("select * from Admin Table")

    mysqlreaqder = mysecondsqlcommand.ExecuteReader()

    While mysqlreaqder.Read
    MessageBox.Show("New Row Inserted")

    End While


    Catch ex As Exception

    End Try

    If mysqlconnection.State = ConnectionState.Connecting Then
    mysqlconnection.Close()
    End If
    Else
    Me.Close()
    End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Me.Close()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    Dim userName As String

    userName = TextBox1.Text

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
    Dim password As String

    password = TextBox2.Text

    End Sub
    End Class


    I don't know whether i successfully connect to SQL server.

    How to check the connection ?


    A billion thanks for your help.
    Last edited by Peter_APIIT; 03-06-2008 at 05:41 AM.

  13. #13
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by Peter_APIIT
    Besides this, i also try another code but cannot insert into the databse.
    What happens when you try?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  14. #14
    Join Date
    Oct 2004
    Location
    Bangalore, India
    Posts
    47

    Connect SQl server using VB.Net

    Hi,

    Step1: Creating the Database Files

    CREATE DATABASE permission defaults to members of the sysadmin and dbcreator fixed server roles.

    Using Object Explorer, creating a new database requires only that the database name be entered in the new database form. We open the form by right-clicking the databases node under a server and selecting New database. On the ‘General’ page, type a name for the database in the Database Name box. Click Ok. A database with the name you entered will be created.

    Step2: Creating Tables using SQL Server Management Studio

    SQL Server Management Studio provides for creating tables or modify existing ones in a graphical environment.

    1. In the Object Explorer expand the Databases Node and select a database.
    2. To create a New Table right click the Tables node and select New Table from the Menu. Access the Table designer.
    3. Select the Properties Window option in the Menu.
    4. Type Name as Customer and Schema as mySchema.
    5. Rows in the Table view correspond to columns in the Table.
    6. Columns include CustID, CustName, and City.
    7. Column properties listed include Name, Data Type and Allow Nulls.
    8. When you are finished creating the Table, save the table.

    Step4: Connecting to a Database through a VB 2005 program

    The first step to using ADO.NET is to connect to a datasource. Using the Connection object, we instruct ADO.NET the database to contact. The Connection object is the gateway to the database, and all the operations performed against the database must go through this gateway. Connection objects expose a number properties and methods to manipulate from within the code. To do that, type the Imports statement for the System.Data.SqlClient name at the top of the form module.

    Dim connectionString As String = “server=SYS2;” + “integrated security=SSPI;” + “database=FinAccounting”

    The connectionString property is a long string with several attributes separated by semicolons. In the above connectionString, server is the name of the SQL Server, or ‘Local’ if you are running SQL Server on the same machine. We can replace the ‘server’ with the word ‘Data Source’ and ‘database’ with ‘Initial Catalog’. Integrated Security is to specify that the connection should be secure. The possible values for Integrated Security are ‘true’, ‘yes’, and ‘sspi’, which specify a secure connection.
    Last edited by Hack; 03-13-2008 at 08:11 AM.

  15. #15
    Join Date
    May 2007
    Posts
    843
    I using sql server 2005 server management studio express.

Similar Threads

  1. find version & service packs
    By rperez in forum Database
    Replies: 5
    Last Post: 01-02-2009, 05:14 PM
  2. Replies: 1
    Last Post: 01-28-2008, 03:18 PM
  3. Connect SQL Server to Hyperion
    By OAP644 in forum Database
    Replies: 1
    Last Post: 06-19-2007, 12:55 PM
  4. Sql Server client not able to connect server
    By Noordeen in forum ASP.NET
    Replies: 0
    Last Post: 08-12-2002, 03:10 AM
  5. Connect SQL Server Box to Oracle Box
    By Mark in forum Database
    Replies: 5
    Last Post: 07-15-2002, 11:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center