locked
connecting to a database in VB.NET RRS feed

  • Question

  • User1767727607 posted

    Hi all

    I am trying to create a connection to database, but when i declare variable like below


    Dim
    conn As SqlConnection = Nothing
    Dim cmd As SqlCommand = Nothing
    Dim ds As DataSet = New DataSet()
    Dim da As SqlDataAdapter = Nothing
     
    Is giving me error,  I know that we have to include system.data.sqlclient, I did that using references, or on the top of the page, but i still get error saying:


    conn and cmd, error message says
    Error 1 'SqlConnection' is ambiguous in the namespace 'System.Data.SqlClient'. C:\Documents and Settings\Mubarak\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb 8 21 WindowsApplication1

    even though the intelisence for SqlConnection does appear when I declare conn as sqlconnection.

     

    Thanks

    Monday, July 28, 2008 11:22 AM

All replies

  • User-1573490007 posted

    I have a feeling that you included a reference to System.Data.SqlClient -twice- (probably 2 different versions). Check your references to be sure its only there once?

    Monday, July 28, 2008 11:25 AM
  • User1330954201 posted

    I think System.Data is included by default so you shouldn't need to add System.Data.SqlClient to your references, you just need to use the 'Imports System.Data' at the top of your code file.

    Tuesday, July 29, 2008 10:58 AM
  • User1202173546 posted

    for these errors you need to use the new statment when declaring a connection string and sqlcomand

    and to conect you have to have values in the varibles like the right conneciton string, and select comand you also have to open the conection string varible

    [;)]

    Tuesday, July 29, 2008 5:10 PM
  • User-1845381400 posted

     hi ,

    I don't think u can use sqlconn the way u have written. u need to use the "new"  keyword to instantiate the connection, even if u r assigning nothing ...

    so u say :dim  conn as new sqlconnection("connectionstring here") or dim conn as sqlconnection() and later conn=new sqlconnection("connectionstring here")

    hope this helps.. 

    Thursday, July 31, 2008 9:03 AM