Multi-valued...cannot be used in a WHERE or HAVING - ms-access-2010

I am not an access professional but use it to help me make my job easier so please excuse my terminology. I will try and explain as best I can.
I need to create a data base that stores the contact and other information about vendors that we use and specifically the services and the countries that they can provide services in but some of these vendors can provide services in multiple countries and can also provide multiple services. So would prefer to be able to use a list with multi-valued entries for ease of use and to prevent having to duplicate the vendor entries for deferment countries and services. (This i can do)
Then i need to create a search form that performs searches on key words, ether the country name, the service or the vendors name. I did this based on the following code i got from the internet:
Private Sub Command9_Click()
Dim strsearch As String
Dim strText As String
strText = Me.TxtSearch.Value
strsearch = "SELECT * from Query1 where ((Decipline Like ""*" & strText & "*"") or (Country_OO Like ""*" & strText & "*""))"
Me.RecordSource = strsearch
End Sub
(The search part in itself works fine)
The problem: When I try to use the search with the multi-valued list
box I get the following error: Error 3831 the multi-valued 'Country_OO'
cannot be used in a WHERE or HAVING clause.
Debug.Print strsearch SELECT * from Query1 where ((Decipline Like "a") or (Country_OO Like "a"))
I know most of you on here are not fans of the Multi-valued list but in this case it would work great. Is there a way around this or and alternative that you can suggest? Maybe a way that i can select the from a list then it adds the txt only to the master file?

Taking your (good!) question title to Google leads directly here, which suggests that
WHERE Country_OO.Value Like "*a*"
should work.
But it would really be better to not use multi-valued fields. Ever.

Related

Data Audit trail for reportviewer SSRS

I want to get an idea about how can i capture the data audit trail of SSRS report getting rendered in Asp.net reportviwer.
I dont want the execution log. Example my report take department as input and give all details of employee working in that department.
Now my requirement is that, lets say i run the report for department a and get some employee then i have to log a audit trail saying i have seen records of so and so employee.
I was thinking that from SSRS itself i can insert the record which are retrieved or to be rendered but what if rendering failed, my log will still say that i have seen the record even before it appearing on ASP.Net page. Second way is that i have to make another call after data is rendered with same parameter and then log the result which can give me wrong result as data might have changed in that small interval.
secondly is there a way to track the save and print event On asp.net reportviewer control
looking forward for ideas. Thanks in advance.
Reporting Services may not be the solution for you if you want to add behaviour to data access. Reports are best as a display of data, not having side effects.
That said, probably the best you can do is to audit the rendering process using custom code. For instance, when you go to display the employee code you call a function recording that it was displayed and by who:
Function AuditEmployeeAccess(EmployeeCode As String) As String
' Connect to database, audit access (off the top of my head, could be bad)
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=MyServer;Initial Catalog=AuditDb;User ID=username;Password=password"
con.Open()
' Don't do this, use parameters
cmd.CommandText = ("insert into audit (AuditEmployeeCode, AccessEmployeeCode) values ('" + Globals!UserId.Value + "', '" + EmployeeCode + "')")
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
' Return the employee code for display in the report
Return EmployeeCode
End Function
then instead of the cell holding the field value, it uses the expression:
=Code.AuditEmployeeAccess(Fields!EmployeeCode.Value)
Now this will audit whenever the employee code renders rather than when it is looked at. For instance, if the report is 5 pages long but the viewer only looks at the first two pages the access will still be audited for those on page 5.
For this reason you are probably better off creating a custom screen rather than using a report.

Date and Time picker in ASP.net

I know this question is on SO a few times already but I cannot find a working or suitable answer.
I want a date picker which includes a time picker. I don't want any fancy frills etc, just something that works. Preferably one control I can drag into the tool box in VS, register at the top and work with. I have been playing around with many versions the last few days and I can't get one to work. They normally seem to include too many files for me or something stupid. A project I am working on now hinges on this stupid thing so any advice would be welcome. I have previously managed to get a calendar control and put some validation on a text-box to pick times. However I cannot take both of these values and enter them into my database as on Date-time field because when I try to use "Selected-date" to get the time it naturally says that text-boxes cannot be members of the "Selected-date" property.
As I have a calendar control in to pick the date and a validated textbox to type in the time I tried to use the following code.
Protected Sub Button1_Click(sender As Object, e As EventArgs)
Dim time As String() = txtTime.SelectedDate.ToString().Trim().Split(" "C)
Dim [date] As String() = cldDate.SelectedDate.ToString().Trim().Split(" "C)
Dim datetime__1 As String = [date](0) & " " & time(1) & time(2)
Dim DateTimeValue As DateTime = DateTime.Parse(datetime__1)
Response.Write(DateTimeValue.ToString())
' Update database with DateTimeValue.
End Sub
The code txtTime.SelectedDate.ToString() is a problem here. It says that SelectedDate is not a supported member of textbox. This is code that I have came across. I'm pretty new to coding.
You could create a new instance of the DateTime structure. The DateTimePicker.SelectedValue returns a Nullable(Of DateTime), so you can use the values of this to create a new DateTime (along with the values from your textboxes).
For example:
Dim myDateTime As New DateTime(cldDate.SelectedDate.Year, cldDate.SelectedDate.Month, cldDate.SelectedDate.Day, HourValue, MinuteValue, 0)
Just replace HourValue and MinuteValue with your values from your textboxes. Note you should convert these to Integers.
Note the 0 at the end represents seconds.
This should save to the database fine.
For more info on DateTime see here.
if jQuery is an option i would look at this plug in
clean and easy to implement
You don't mention whether a commercial product would be an option for you.
We are using telerik's RadDateTimePicker in our projects (and there are certainly other commercial products). See this page for a demo of the datetime picker control.

Web scraping a telephone number

I am new to the HtmlAgilityPack and its a bit unclear for me how it exactly works. Lets say when something like this piece of code is written
Dim url1 As String = "http://www.bing.com/search?q=Verizon
Dim hw As New HtmlWeb()
Dim doc As HtmlDocument = hw.Load(url1)
For Each link As HtmlNode In doc.DocumentNode.SelectNodes("//a[#href]")
Dim att As HtmlAttribute = link.Attributes("href")
Response.Write(att.Value)
Next
So when the SelectNodes is //a[#href] does that mean that it will only look at ahref tags?
If so how can I make it consider other tags in within the loop like <li>, <h3>, <div>.
Is it correct like //li[#class='wrap']|//div[#class='last'] ??
How can the data between those tags be fetched and presented.
One other issue is that lets say I need to scrape a telephone number from that url, the number might be unavailable or might not be in any of the tags defined. Is there any reliable method that I can work on in order to obtain a telephone number to a relative search term? Any suggestions or thoughts?
Indeed, the current xpath looks at anchor tags that have a href parameter. I suggest you read up on xpath syntax (for instance at http://www.w3schools.com/xpath/xpath_syntax.asp)
To select other nodes you need to change the xpath to select those tags, for instance:
doc.DocumentNode.SelectNodes("//li")
to get all li nodes etc.
The data in the tags can be reached using the InnerHtml of the selected document nodes (link.InnerHtml in your example)
Automatically scraping telephone numbers is a real pain, every country uses different lengths and there are many different formats to write down a number: +12(0)3456 +123456 00123456 +12(0)34-56 are all the same valid phone number... See Check if there is phone number in string C# for a simple sollution
GL&HF!

In ASP.net, How To Create a Dataset From an API Call That Returns XML but Select Specific Nodes

I am trying to make an API call to google places and google returns an XML document with multiple fields and lines of data. What is the best way to take that data, select specific nodes from it, and put it into a dataset?
Here is an example of my API call with control parameters passed into the API call:
("https://maps.googleapis.com/maps/api/place/search/xml?location=" _
& lat & "," & lng & "&radius=5000&keyword=" & Replace(searchvenuenametextbox, " ", "+") _
& "&sensor=false&key=" & googleapikey)
The best way to do this is preferred.
LINQ is the easiest way to do that. query the XML , just taking out the elements that you want then they can be easily inserted into DataTable
Here's a walkthrough that describes how to read Xml into a Dataset: Walkthrough: Reading XML Data into a Dataset
The walkthrough doesn't describe how to omit fields from the Xml prior to adding to your Dataset, however you can use (or not use for that matter) whatever fields you want/don't want from your Dataset.
As for the best way - that's up for debate I suppose.

vb.net to reduce code for displaying data in textboxes

On the page I have created I have a search facility that if a doctors number is searched it will bring up the doctors details, once search button is clicked the results are displayed in textboxes (I cannot use gridviews because this is not wanted)
sample of code placed on the search button
Query statement = "SELECT DocNumber FROM tblDoctor WHERE DNum LIKE '%"
execute the query and get the result
The result is converted to string and Execute Scalar is used
DocNum.Text = Result1
Query statement = "SELECT DocName FROM tblDoctor WHERE DNum LIKE '%"
execute the query and get the result
The result is converted to string and Execute Scalar is used
DocName.Text = Result2
etc.... there are are 14 other textboxes that I want too display data in, so there is a large amount of repeated lines of code following the structure above. Can anyone suggest a better way of doing this?
Another problem of repetition of code comes from the prev page that is linked to it. The page before has a summary of details of doctors, once the row is clicked it takes you to this page displaying a more detailed view of their personal details. The doctor number selected will be passed onto the more detailed view using a querystring so I have the code
Automatic population of the selected doctors will fill the labels
on page load
Request the query string and store into variable dNum
Query statement = "SELECT DocNumber FROM tblDoctor WHERE DNum = " & dNum"
Get result from query convert to string and use execute scalar
lblDocNum.Text = Res1
Query statement = "SELECT DocNumber FROM tblDoctor WHERE DNum = " & dNum"
Get result from query convert to string and use execute scalar
lblDocNum.Text = Res1
etc...
What I am doing works correctly but the coding style looks poor. Any help would be much appreciated.
Thank you
Why not use a DataReader or DataSet or whatever you prefer to return the whole record, then simple move from column to column and populate the textboxes that way? Instead of returning one value at a time.
If the goal is less code,
SELECT * FROM tblDoctor WHERE xxx
into a DataTable or DataReader, as Thyamine suggested, above.
From there, you could also put the textboxes in an HTML table in a Repeater which you will bind to that datatable. You won't have to individually assign any of the values, the databinding will do it for you!
I know that people think HTML tables are evil but it's the easiest way to line up the labels I assume you will also want.
I also know that the control I suggested is called a Repeater but you only have one record. If you don't tell the compiler, I won't. :)
From parts of your question, it sounds like you're wondering whether to send all of the bits of information along in the querystring but that doesn't sound like a good idea to me because it invites users to mess with the data in the querystring.
You didn't mention - are these textboxes meant for editing? A Save button inside the Repeater would have easy access to all of the controls to build your update statement. You could also put the Save button outside the repeater and refer to the repeater's first Item to find the controls.

Resources