|
eshban284 wrote:
Dim da As New SqlClient.SqlDataAdapter("SELECT * from books where '" & Me.ComboSearch.Text & "' like '" & var1 & "' ", cn)
You're putting quotes around the tablename. You shouldn't.
Also, LIKE doesn't do anything unless you put % on either side of the string. And finally, you're wide open for SQL injection attacks with this code.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Also, LIKE doesn't do anything unless you put % on either side of the string
% is the wildcard so having Like 'A%' searches for anything beginning "A" - it is not necessary to have the wildcard on either side.
|
|
|
|
|
Christian Graus wrote:
You're putting quotes around the tablename. You shouldn't.
I think you mean column name and not table name. And to clarify, you shouldn't be putting single quotes around the column name.
|
|
|
|
|
Hi,
Thank you for your reply. Now my code runs fine. I just exclude single quotes. As far as like operator is concerned, i concat the % sign with the alphabets like A,B or C etc.
Thank you
EsHbAn BaHaDuR
|
|
|
|
|
I have an Explorer-Style ListView and I use
ListView1.View = View.Details<br />
ListView1.View = View.LargeIcon<br />
ListView1.View = View.List<br />
ListView1.View = View.SmallIcon
to update the respective view.
I added the ability to view thumbnails with this code:
Dim fullPath As String
Dim di As New DirectoryInfo(fpath)
Dim fi As FileInfo
Dim i As Integer
fullPath = GetPathFromNode(TreeView1.SelectedNode)
ListView1.Items.Clear()
'*** Loop to get the "jpg" files
Try
For Each fi In di.GetFiles("*.jpg") ' if path will contain link files, change from jpg to lnk
ImageList3.ImageSize = New Size(96, 96)
Try
CreateThumbNail(fpath & "\" & fi.Name) ' This returns the thumbnail images
With ListView1 ' set the properties for for the ListView ListView1
.Items.Add(fi.Name, i)
.LargeImageList = ImageList3
.ForeColor = Color.Blue
.Scrollable = True
End With
Catch
Exit Try
End Try
i += 1
Next ' cycle through fpath until no more *.jpg.lnk files are found
Catch
MsgBox("No image files are located in this directory.", MsgBoxStyle.Exclamation, "Thumbnails")
Exit Try
End Try
Private Sub CreateThumbNail(ByVal filepath As String)
Dim myImage As New Bitmap(filepath)
Dim MyThumbNail As Image
'*** ThumbNail
MyThumbNail = myImage.GetThumbnailImage(96, 96, AddressOf Thumbnailabort, Nothing)
'*** Fill the ImageList with Image Collection
ImageList3.Images.Add(MyThumbNail)
End Sub
The four ListView1.View = * work just fine until I execute the routine to view thumbnails. After viewing thumbnails the four ListView1.View = * routines do not work properly. Among the problems is that only jpg’s are listed in the ListView.
Any ideas or suggestions?
Thanks
Brad
|
|
|
|
|
I have a Names datatable with FirstName and Namesid columns. I'm using the following code to drive the list for the combobox.
ComboBox1.DataSource = "DataSetNames"
ComboBox1.DisplayMember = "name.firstname"
I have an Orders datatable with OrderDate and Namesid columns. When a name is choosen form the combobox list how do I write the corresponding Namesid back to the Orders table Namesid column?
Thanks in advance for any help.
|
|
|
|
|
Add this to your binding:
ComboBox1.DataSource = "DataSetNames"<br />
ComboBox1.DisplayMember = "name.firstname"<br />
ComboBox1.ValueMember = "name.Namesid"
Then when you select an item in the combox...you can return
ComboBox1.SelectedValue
which should contain the corresponding Namesid.
|
|
|
|
|
I have a textbox where a user enters his/her id number. After a click event, I want to take that id number and compare it to the id that is stored on my sql server database table, then allow the user to either proceed or stop. Any ideas how to do that?
Shannon P.
|
|
|
|
|
Use SQL to check if the value is in the table. Use the result of the SQL to decide what to do next.
More specific help would require an idea of your overall setup, and which part of this task is causing you problems.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
What I'm attempting to do is to validate what a user's id is within a textbox with what is stored within the sql server database. If the id on the textbox matches what is inside the database, begin the application. If not, display an error message to user. That is what I'm attempting to do. Any ideas would be greatly appreciated.
Shannon P.
|
|
|
|
|
Christian gave you an idea that would work. What's the problem?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
My problem begins at "myCommand.ExecuteScalar()". My try...catch error handler reads, "Invalid object name: EmpId". My table has a column labeled "EmpId" so I'm not actually sure what the problem is. Any ideas?
Shannon P.
Dim myConnection As New System.Data.SqlClient.SqlConnection
myConnection.ConnectionString = "workstation id=SHANNON-OUYIJ2M;packet size=4096;integrated security=SSPI;data source=SHANNON-OUYIJ2M;persist security info=False;initial catalog=WorkInstructionLibrary"
'Create a parameterised command that will return the number of matches.
Dim myCommand As New SqlCommand("SELECT COUNT(*) FROM EmpID WHERE EmpID = @employeeId", myConnection)
'Set the parameter values to the credentials entered by the user.
myCommand.Parameters.Add("@employeeId", SqlDbType.Int).Value = Me.txtEmpId.Text
myConnection.Open()
Try
Dim count As Integer
count = CInt(myCommand.ExecuteScalar())
If count = 0 Then
'generic fail message
Else
'allow application to proceed
End If
Catch ex As SqlException
Dim errorMessages As String
Dim i As Integer
For i = 0 To ex.Errors.Count - 1
errorMessages += "Index #" & i.ToString() & ControlChars.NewLine _
& "Message: " & ex.Errors(i).Message & ControlChars.NewLine _
& "LineNumber: " & ex.Errors(i).LineNumber & ControlChars.NewLine _
& "Source: " & ex.Errors(i).Source & ControlChars.NewLine _
& "Procedure: " & ex.Errors(i).Procedure & ControlChars.NewLine
Next i
Dim log As System.Diagnostics.EventLog = New System.Diagnostics.EventLog
log.Source = "My Application"
log.WriteEntry(errorMessages)
Console.WriteLine("An exception occurred. Please contact your system administrator.")
MessageBox.Show("Error: EXECUTESCALAR METHOD" & errorMessages.ToString & " <> " & ex.ToString, "Error executing EXECUTESCALAR METHOD", MessageBoxButtons.OK)
End Try
|
|
|
|
|
Found the solution! My EmpId should have been my table name. Stupid syntax error on my part! Thanks to all.
Shannon P.
|
|
|
|
|
hi,
i want to make a program that will stand between a program i use and the server it connects to so i can see the packets moving between them.
the question is, how i make my program redirect the ip:port of the other program to go through it ?
should i use winsock ? inet ? in which way ?
any suggestions ?
|
|
|
|
|
If you want to write it yourself, you have two options. You can either write your own proxy or your own network monitor. Either way, it's alot of work. Or you can use the Network Monitor that comes with Windows Servers.
No matter what, I would suggest Googling for "network packet capture windows". Clickety[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Does anybody know if there is a (one command) way to change the BackColor of all controls in a form as well as the form itself?
I have an application with several forms and controls and I want to “spruce up” the look a little bit.
Thanks
Brad
|
|
|
|
|
Nope. You'll have to enumerate all the controls on the form and change them, one by one.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Okay...that's what I was affraid of.
Thanks.
|
|
|
|
|
Is it possible to create a MultiLine list box?
Any references that could point me in the right direction? Thanks!
|
|
|
|
|
Do you mean add items?
Here is how you add items:
lstBoxAddItem.Items.Add
|
|
|
|
|
|
This is the source code
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data.SqlClient
Imports System.Data
Private str_connection As String = "workstation id=""MAX-IT10Q0"";packet size=4096;integrated security=SSPI;initia" & _
"l catalog=Addressbook;persist security info=False"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnsql As SqlConnection
Dim load_dataset As New DataSet
Dim rpt As ReportDocument
Dim str_query As String
rpt = New ReportDocument
rpt.Load("..\CrystalReport2.rpt")
cnsql = New SqlConnection(str_connection)
cnsql.Open()
str_query = "select name,Address from tb_abook"
Dim load_adapter As New SqlDataAdapter(str_query, cnsql)
load_adapter.Fill(load_dataset, "tb_abook")
rpt.SetDataSource(load_dataset)
CrystalReportViewer1.ReportSource = rpt
End Sub
Report :Crystelreport 9.0
Os: XP
visual studio.net 2003
Continue...
|
|
|
|
|
Hi everyone,
I was just wondering if anybody knows the answer to this as i have looked and found nothing.
I have a form with several controls on it, i want to catch the keypress - easy enough but for all controls including the form not just the one with focus. The only way i can see is to add the event for every control, but i have about 75 controls on this form and this just doesn't seem logical.
any ideas
help is greatly appreciated.
"If i was king cigarettes would be free."
|
|
|
|
|
Your form and a majority of controls in .NET should already have a KeyPress event. It's up to you to put code into those events to perform whatever action/task you want to accomplish.
|
|
|
|
|
Sorry I read wrong...but other than placing code in the KeyPress event...it really depends if you are doing a specify task for that control. If each task is different...I don't see a way around this.
Plus, if you just capture the KeyPress on the Form you will still have to delegate the task to some event/sub of that control and knowing which one to delegate to could be a real mess!
|
|
|
|