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

  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
    May 2007
    Posts
    843
    I using sql server 2005 server management studio express.

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

    I have check the server explorer but i didn't see any table which i craete in server management studio.

    where is the app.config/web.config ? I want to check my connection string
    Last edited by Peter_APIIT; 03-06-2008 at 06:20 AM.

  15. #15
    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

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