Crystal report asks database password and set date format in formula - sql

I have two problems:
When I want printout the Crystal Report, get data from SQL using formula, it always requires database password, can I save my password or open connection string using VB?
When I get the data from database the date format is like 1986-01-01 01:00AM. Can I make it like 1986-01-01 only?
Code:
'CrystalReportViewer1.ReportSource = New CrystalReport3
'CrystalReportViewer1.SelectionFormula = "{PersonalData.IDNo}='" + Information.TextBox18.Text + "'"

Related

Retrieve Log In username and output initials based on a table in Access database

I'm improving an old Access database used to log our receiving inspection reports.
There is a textbox in the report labeled "Inspector Initials". A technician, who has now left the company, wrote a code to retrieve the username and output their initials as a default value.
I tried to recover the database built with it but I can not find it.
I tried formulas and macros to pull this data.
I tried codes that found one other sites/forums.
This used to work.
Function UserNameWindows() As String
UserName = Environ("USERNAME")
End Function
I would like to retrieve the login username through Outlook, reference the "Initials" table and output that user's initials.
with the assumption that you are using active directory (which is standard in most business environments)
Public Function UserNameWindows() As String
With GetObject("LDAP://" & CreateObject("ADSystemInfo").Username)
UserNameWindows = .samaccountname
End With
End Function

how to get date format for excel using xlrd?

Our requirement is like to import data from excel and display in web. while importing I m able to convert it into any format(like dd-mm-yy) but requirement is like it should display the same format as defined by user.
So if can get the formatting info, we can format using datetime module pf python.
Thanks in Advance
First verify oledb connection string
conn.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nick\Desktop\Pricing2.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=1;""
To always use IMEX=1 is a safer way to retrieve data for mixed data type columns...
Range rg = (Excel.Range)worksheetobject.Cells[1,1];
rg.EntireColumn.NumberFormat = "MM/DD/YYYY";
this used for validate column date type or not.
Before Save using method in C#
Datetime.TryParseExact();
That method return Datetime ,First leran that method before try it.

Crystal report missing parameter values when export

When I ran my crystal report, I run into an error where its shows missing parameter values
Below is my code
_crAdviceRpt.Load("C:\Users\whatever\AD_AdviceTemplate.rpt")
Dim ds As ADDataset = New ADDataset
Dim dt As DataTable = ds.Tables.Add("ADDatatable")
dt.Columns.Add(New DataColumn("strLinesList", Type.GetType("System.String")))
Dim dr As DataRow
dr = dt.NewRow
dr("strLinesList") = strLine
dt.Rows.Add(dr)
_crAdviceRpt.SetDataSource(ds.Tables(1))
CrDiskFileDestinationOptions.DiskFileName = "location.pdf"
CrExportOptions = _crAdviceRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
_crAdviceRpt.Export()
If Not _crAdviceRpt Is Nothing Then
_crAdviceRpt.Close()
_crAdviceRpt.Dispose()
_crAdviceRpt = Nothing
End If
In my dataset, it does like this:
ADDDataset.xsd-> ADDatatable -> strLinesList
strLinesList is my column over here
In crystal report designer, I drag the strLinesList over to my .rpt
I'm not sure what is wrong but I'm pretty sure that something is missing in my code, so anyhere is appreciated
The Solution for this is to reorder the Crystal Parameters to match the Query Prompts
1) Open the problem report in Crystal Designer
2) Right click the Parameters section and select reorder parameters
3) Set the Parameter order to match that of the Prompts in the query
4) save the report and retest
The Verify Database command on the Database menu checks the alias pointers stored in a report file to verify that the database files expected are located in the indicated directories. If the databases are not found in the specified location, the program notifies you of the discrepancies.
Using the Verify Database process
When you choose Verify Database from the Database menu, the program checks the active databases and reports. If it detects changes, the report must be adapted to prevent errors. The program displays the Map Fields dialog box when it detects either of these types of changes to the database:
- The name of a database field that is used in the report has changed
- The database has been upsized from a PC data source to an SQL data source.
Crystal Reports automatically adapts the report (and does not display the Map Fields dialog box) if it detects any of these changes:
- Fields have been added to the database
- Fields that are not used in the report have been deleted from the database
- Field positions have changed in the database
- Data types have changed for fields in the database.
Using the Verify on Every Print process
Verify on Every Print triggers the Verify Database command every time you print your report.
- If there is a check mark beside Verify on Every Print, the option is active. It triggers Verify Database every time you print.
- If there is no check mark beside it, the option is inactive. The option is inactive by default.
Link

ASP Classic Webapp - Connect to different SQL DB via login

Need a way to connect to a unique SQL db via login in ASP classic.
THE SETUP
Webapp: ASP classic/SQL 2005.
Webapp stores information for multiple companies.
All data stored in one master SQL 2005. All db's will be on same server.
Each user has a unique login (Company, User ID, Password)
Connection is with master db include file using DSN-less connection
IE: (dbConn.Open "driver={SQL Server};server=11.22.333.444;database=mywebdb","mylogin","mypassword")
THE NEED:
Want to split companies into their own database. When the user logins, the company name will tell the APP to use a unique SQL db connection for each company.
Since dynamic include files are not an option, what is best route to go?
Thank you!
The connection string must be stored some where right? A include .asp I guess.
Add code in that include to examine the company name (stored in the session?) and fixup the connection string accordingly.
Edit:
The issue is you may have code out there in a myriad different ASP pages that assumes the appropriate connection string is available in a variable declared in you db.asp include file (lets call it m_connStr). You don't want to have to modify all these pages in order to meet this new requirement.
Thus you only want to edit the db.asp include file and you just want m_connStr to magically point at the correct DB.
Have your logon page once you know the company set the database name in a Session variable.
Your existing code has the connection string like this:-
m_connStr = "driver={SQL Server};server=11.22.333.444 database=mywebdb", "mylogin", "mypassword"
So we'll use a template:-
m_connStrTemplate = "driver={SQL Server};server=11.22.333.444 database=%db%", "mylogin", "mypassword"
If Session("database") <> "" Then
m_connStr = Replace(m_connStrTemplate, "%db%", Session("database"))
End If
Note a non-existant database session variable causes the connection string to not be defined hence you can't accidentally connect to a default database.
Now as far as all your ASP pages are concerned it's business as usual but the connection string will vary by session according to the company associated with the logged on user.
However you do it, you'll end up varying your connection string based on user input. Don't use user input directly, but validate it against a list of acceptable values. I suggest a Select Case statement to do this:
' Do this when logging in: '
Dim companyName
companyName = Request.Form("companyName")
Select Case companyName
Case "company1"
Session("companyDB") = "company1"
Case "company2"
Session("companyDB") = "company2"
Case Else
Session.Contents.Remove("companyDB")
' Invalid login! '
End Select
' Do this when connecting to the database: '
Dim connectionString
If Session("companyDB") Then
connectionString = "...database=" & Session("companyDB") & "..."
Else
' Invalid login, go log in again '
End If
Keep in mind that this will lead to trouble if you have users who will want to open one company in one tab and another company in another tab. They are going to wonder why they can only see information for the company they logged into most recently.
If this is going to be an issue, you will probably want to pass a token around in the query string on each link. This adds complexity, but not terribly much (aside from the tedious task of changing every link). It would then look like this:
' Do this when logging in: '
Dim companyName
companyName = Request.Form("companyName")
Select Case companyName
Case "company1"
Session("company1 - db") = "company1DBName"
Case "company2"
Session("company2 - db") = "company2DBName"
Case Else
' Invalid login! '
End Select
' Do this when connecting to the database: '
Dim connectionString, companyToken
companyToken = Request("companyToken")
If Session(companyToken & " - db") Then
connectionString = "...database=" & Session(companyToken & " - db") & "..."
Else
' Invalid login, go log in again
End If
This assumes that the token will be the same as the company name, for simplicity. So, for instance, somebody will log in for "company1." Having done so successfully, they get a session variable called "company1 - db", which contains the name of the database (in this case, "company1DBName").
Now, every link they follow should have a query string, like "?companyToken=company1" So, when you are connecting to the database, you take that token and use it to find the right database name: Session("company1" + " - db") = "company1DBName"
If they haven't logged in to that company yet (or if they just make up a company name), they won't have that session variable, and they have to go to the log in screen.
If they log in under two companies at once, you can now handle it because you'll be obtaining the database name on every link.
Make sense?
Whatever you do, do not use the user input to create the connection string directly. In other words, the following is the wrong way:
Dim connectionString
connectionString = "...database=" & Request.Form("companyDB") & "..."
Good luck!

Open FoxPro Table in VB.net 2005

I need to open foxpro free tables in vb.net using the oledb connection.
But... I only need to get the column names. I don't really need to 'select' anything.
I am trying to dynamically browse through all our free tables and set up a listing of every column from every file and xref that to another free table that contains a description of each column.
I have a working model now, but it requires that I do...
SELECT TOP 1 FROM "File" ORDER BY 1
But on the largest table, it takes over two minutes just to read in the first record and there are over 250 tables. Overall, it takes between 15 and 20 minutes.
Or, is there another way to only get the first record of the table without using 'ORDER BY'?
Here's what I have so far. "File" is passed in as a parameter.
It would contain info like "C:\data\table1.dbf"
Dim filePath As String
filePath = IO.Path.GetDirectoryName(file)
myOledbConnection = New OleDbConnection("Provider=VFPOLEDB.1;Data Source=" & filePath & ";Collating Sequence=MACHINE")
myOledbCommand = New OleDbCommand
myOledbDataAdapter = New OleDbDataAdapter
Dim fields, from, order As String
fields = "select top 1 *"
from = " from " & file
order = " order by 1"
myOledbCommand.CommandText = fields & from & order
myOledbCommand.Connection = myOledbConnection
myOledbDataAdapter.SelectCommand = myOledbCommand
myOledbDataAdapter.Fill(dt)
I then take the datatable (dt) and loop through to get the column information.
I would like it to be as quick as Visual Studio is when I create a dataset and load all tables from the directory through the wizard. It is able to very quickly find all the column information without reading in the data from the table.
Let me know if you need more information.
Thanks.
Why do you need to get any records at all? You should be able to say:
SELECT * FROM "File" where 1 = 0
This will give you an empty result set, will also give you metadata on the projection returned.
You might also want to look into the GetOleDbSchemaTable method on the OleDbConnection class, as it will allow you to get information about the schema of the database without having to perform a query.
You can also use the Microsoft ADO Extensions for Data Definition Language and Security through COM interop (mxADOX.dll) to get the schema information as well.
I have not tried this/. But, it looks like the way to go.
Specifically the "GetSchema" method on OleDbConnection instance.
http://msdn.microsoft.com/en-us/library/ms254934(VS.80).aspx