VB.net with sql server 2008

April 24, 2009 at 10:48:33
Specs: Windows XP
I am using VS 2008's VB.net and want to connect to SQL server 2008....I am new to SQL server so please help. What are the things I need to install for SQL server to run compatible to VB.NET

See More: VB.net with sql server 2008

Report •

April 24, 2009 at 11:51:10
Greetings Maina,

I am not a very experienced programmer but I would like to try to help in some way.

If you have SQL Server 2008 and Visual Studio 2008 installed, then you should be able in a code-behind page to connect to the database.

I have used Visual Studio 2005 web app to connect to a SQL Server 2000 db.

I have used VB in the code-behind but not C#.

You could have something like the following in the web config of the web app:

      <add key="Security" value="Data Source=KVCSQL;Initial Catalog=appSecurity; Integrated Security=True" />
      <add key="DSN" value="Data Source=SQL-BETA;Initial Catalog=Transportation;Integrated Security=True" />
      <add key="ClientKS" value="Data Source=SQL-BETA;Initial Catalog=Client_KS;Integrated Security=True" />
      <add key="Portal" value="Data Source=SQL-BETA;Initial Catalog=Portal;Integrated Security=True" />
      <add key="sitePath" value="/Transportation" />
      <add key="SID" value="28" />
      <add key="emailTesting" value="Y" />
      <add key="CrystalImageCleaner-AutoStart" value="true" />
      <add key="CrystalImageCleaner-Sleep" value="60000" />
      <add key="CrystalImageCleaner-Age" value="120000" />
    <add name="TransportationConnectionString" connectionString="Data Source=SQL-Beta;Initial Catalog=Transportation;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="Client_KSConnectionString" connectionString="Data Source=SQL-Beta;Initial Catalog=Client_KS;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="appSecurityConnectionString" connectionString="Data Source=KVCSQL;Initial Catalog=appSecurity;Integrated Security=True" providerName="System.Data.SqlClient"/>
 <add name="Portal" connectionString="Data Source=SQL-Beta;Initial Catalog=Portal;Integrated Security=True" providerName="System.Data.SqlClient"/>

Then in a code-behind page using VB, you could have something like the following to connect to a SQL Server db:

  Public Con_ClientKS As New Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("ClientKS").ToString())

Then somewhere in that code-behind page you could have the following:

 Dim cmdChildInDb As Data.SqlClient.SqlCommand
                            Dim dtrChildInDb As Data.SqlClient.SqlDataReader
                            cmdChildInDb = New Data.SqlClient.SqlCommand _
                                ("SELECT plctype, age, csmgrname " _
                                & "from masterfile where csnbr = " & "'" & Session("csnbrToEdit") & "'", Con_ClientKS)
                            dtrChildInDb = cmdChildInDb.ExecuteReader()
                            While dtrChildInDb.Read() = True
                                If dtrChildInDb("age").ToString() <> "" And dtrChildInDb("age") Is DBNull.Value = False Then
                                    Me.txtAge.Text = dtrChildInDb("age")
                                End If
                                If dtrChildInDb("plctype").ToString() <> "" And dtrChildInDb("plctype") Is DBNull.Value = False Then
                                    Me.txtPlcType.Text = dtrChildInDb("plctype")
                                End If
                                If dtrChildInDb("csmgrname").ToString() <> "" And dtrChildInDb("csmgrname") Is DBNull.Value = False Then
                                    Me.txtCaseMgr.Text = dtrChildInDb("csmgrname")
                                End If
                            End While

Maybe I am not understanding your problem correctly though and do not know correctly what are your intentions.

Report •
Related Solutions

Ask Question