473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Switch Database

I have a stored procedure as follows which extracts data from a view:

SELECT NameEn, Code, COUNT(*) AS Total
FROM dbo.vwu_Reports
Group By NameEn, Code
ORDER BY NameEn, Code

i have created similar Views and stored procedure for all the other database (database names depict the location)

how do i switch in VB.NET to the different database (location) upon selecting the location from a comboBox. I am using crystal report 9 for reporting.

Could u please help me get it working ..... i am really stuk and getting behind schedule.

the VB.NET code looks something like this:
Expand|Select|Wrap|Line Numbers
  1. Public Sub SetLogonInfo()
  2.     Try
  3.         LogInfo.ConnectionInfo.ServerName = strDataSource
  4.         LogInfo.ConnectionInfo.UserID = strUserId
  5.         LogInfo.ConnectionInfo.Password = strPassword
  6.         LogInfo.ConnectionInfo.DatabaseName = strDatabase
  7.     Catch ex As Exception
  8.             MessageBox.Show(ex.Message)
  9.     End Try
  10. End Sub
  11. Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.  
  13.         Dim objReport As New SummaryRpt
  14.         Dim DT As New DataTable
  15.         'Dim CmdStr As String
  16.         Dim sqlConnection1 As New SqlConnection
  17.         'Dim sqlDataAdapter1
  18.         Dim sqlSelectCommand1 As New SqlCommand
  19.  
  20.         strDatabase = "Location 1"
  21.         SetLogonInfo()
  22.  
  23.         'sqlConnection1.ConnectionString = "Data Source=" & strDataSource & ";USER ID=" & strUserId & ";pwd=" & strPassword & ";Initial Catalog=" & strDatabase
  24.  
  25.         'Try
  26.         '    CmdStr = "Select * From SummaryReports"
  27.         '    sqlConnection1.Open()
  28.         '    sqlDataAdapter1 = New SqlDataAdapter(CmdStr, sqlConnection1)
  29.         '    DT.Clear()
  30.         '    sqlDataAdapter1.Fill(DT)
  31.         '    sqlConnection1.Close()
  32.         'Catch ex As Exception
  33.         '    MessageBox.Show(ex.Message)
  34.         'End Try
  35.  
  36.         'objReport.Database.Tables(0).SetDataSource(DT)
  37.         CrystalReportViewer1.ReportSource = objReport
  38. End Sub
May 16 '07 #1
1 1087
dip_developer
648 Expert 512MB
I have a stored procedure as follows which extracts data from a view:

SELECT NameEn, Code, COUNT(*) AS Total
FROM dbo.vwu_Reports
Group By NameEn, Code
ORDER BY NameEn, Code

i have created similar Views and stored procedure for all the other database (database names depict the location)

how do i switch in VB.NET to the different database (location) upon selecting the location from a comboBox. I am using crystal report 9 for reporting.

Could u please help me get it working ..... i am really stuk and getting behind schedule.

the VB.NET code looks something like this:
Expand|Select|Wrap|Line Numbers
  1. Public Sub SetLogonInfo()
  2.     Try
  3.         LogInfo.ConnectionInfo.ServerName = strDataSource
  4.         LogInfo.ConnectionInfo.UserID = strUserId
  5.         LogInfo.ConnectionInfo.Password = strPassword
  6.         LogInfo.ConnectionInfo.DatabaseName = strDatabase
  7.     Catch ex As Exception
  8.             MessageBox.Show(ex.Message)
  9.     End Try
  10. End Sub
  11. Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.  
  13.         Dim objReport As New SummaryRpt
  14.         Dim DT As New DataTable
  15.         'Dim CmdStr As String
  16.         Dim sqlConnection1 As New SqlConnection
  17.         'Dim sqlDataAdapter1
  18.         Dim sqlSelectCommand1 As New SqlCommand
  19.  
  20.         strDatabase = "Location 1"
  21.         SetLogonInfo()
  22.  
  23.         'sqlConnection1.ConnectionString = "Data Source=" & strDataSource & ";USER ID=" & strUserId & ";pwd=" & strPassword & ";Initial Catalog=" & strDatabase
  24.  
  25.         'Try
  26.         '    CmdStr = "Select * From SummaryReports"
  27.         '    sqlConnection1.Open()
  28.         '    sqlDataAdapter1 = New SqlDataAdapter(CmdStr, sqlConnection1)
  29.         '    DT.Clear()
  30.         '    sqlDataAdapter1.Fill(DT)
  31.         '    sqlConnection1.Close()
  32.         'Catch ex As Exception
  33.         '    MessageBox.Show(ex.Message)
  34.         'End Try
  35.  
  36.         'objReport.Database.Tables(0).SetDataSource(DT)
  37.         CrystalReportViewer1.ReportSource = objReport
  38. End Sub
dynamically you have to change the Connection string....In your case change the strDataSource according to the Selected Item of combobox...
May 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: JaNE | last post by:
I'm trying to get some data from MySql database and to create switch based on those data, but as an php beginer, I have no clear idea how to do this. have tryed many options which loked promising,...
3
by: Mike Wiseley | last post by:
I created a desktop shortcut with "C:\Program Files\Microsoft Office\MSAccess.exe" "C:\My Documents\CopyAToB.mdb" /pwd "password: The trouble is that when running this shortcut, it prompts first...
3
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. ...
14
by: Chris | last post by:
Hi, can you specify a range in a switch - statement ? switch (i) { case 100 - 999 : // do something break; case 1000 - 9999:
5
by: Phuff | last post by:
Hey all, I need some direction help. I have a switch case statement that is seemingly my only option right now, but its too large and not easy to maintain the code. Here goes... I have part...
9
by: Eugene F | last post by:
The database is currently in the circular logging mode (no log archiving). I want to track the database transaction log switch history in form of (switch-timestamp, active-log-sequence-number) to...
6
by: asadikhan | last post by:
Hello, I have a bit of a design issue around this application I am developing, and I just want to run it through some of the brains out here. So I have a table called ErrorCheck which...
2
by: Miyagi | last post by:
I have a bunch of conditions in which to determine different types of questions to ask in a survey I am constructing. Just was wondering if anybody has used a two-dimensional switch statement. If...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.