Computing.Net > Forums > Database > VB.net with sql server 2008

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

VB.net with sql server 2008

Reply to Message Icon

Name: MAINA
Date: April 24, 2009 at 10:48:33 Pacific
OS: Windows XP
Subcategory: MS SQL Server
Comment:

Hi
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



Sponsored Link
Ads by Google

Response Number 1
Name: Hviezdoslav
Date: April 24, 2009 at 11:51:10 Pacific
Reply:

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:

 <appSettings>
      <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" />
    </appSettings>
  <connectionStrings>
    <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"/>
  </connectionStrings>

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)
                            Con_ClientKS.Open()
                            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
                            dtrChildInDb.Close()
                            Con_ClientKS.Close()

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


0
Reply to Message Icon

Related Posts

See More


Importing mail form infor... Opening .tmp file in .jnt


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: VB.net with sql server 2008

SQL Server Reporting Services www.computing.net/answers/dbase/sql-server-reporting-services/722.html

problem with sql server 2000 DSN www.computing.net/answers/dbase/problem-with-sql-server-2000-dsn/380.html

DSN Configuration - SQL Server www.computing.net/answers/dbase/dsn-configuration-sql-server/250.html