|
See if this works:
Select * from rabotnici where rabotnik_name = @rabotnik_name and data_rabota >= @data_rabota and data_rabota <= @data_rabota1
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I try this but also not work again this error
|
|
|
|
|
Access (Jet) doesn't use named parameters, only question marks. You have to specifiy the parameters values in the order the question marks show up in the SQL statement.
|
|
|
|
|
Now that I am looking at this a little closer.
ivo75 wrote:
aCmd.Parameters.Add(param1)
aCmd.Parameters.Add(param2)
aCmd.Parameters.Add(param3)
aCmd.ExecuteNonQuery()
This is wrong since this is a query (select * from = a query).
ivo75 wrote:
aCmd = New OleDbCommand(strQuery, aCon)
Dim da As New OleDbDataAdapter
da.SelectCommand = aCmd
strQuery didn't get changed.....should this command be the same as the first cmd? What is the purpose of the first command?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Few comments:
- when doing select, don't use ExecuteNonQuery. Use for example ExecuteReader. However, since you later use adapter.fill you dont't need to execute anything at that point
- when assigning values to the parameters, don't modify their datatype unless the datatype in database is different. So instead of param2.Value = DateTimePicker1.Value.ToShortDateString use param2.Value = DateTimePicker1.Value
- also you created a new command and used it instead of the command where you added the parameters
So your code could be something like:
...
strQuery = "Select * from rabotnici where rabotnik_name=? and data_rabota>=? and data_rabota<=?"
param1 = New OleDbParameter("@rabotnik_name", OleDbType.VarWChar, 100)
param1.Value = ComboBox1.Text
param2 = New OleDbParameter("@data_rabota", OleDbType.Date)
param2.Value = DateTimePicker1.Value
param3 = New OleDbParameter("@data_rabota1", OleDbType.Date)
param3.Value = DateTimePicker2.Value
aCmd = New OleDbCommand(strQuery, aCon)
aCmd.Parameters.Add(param1)
aCmd.Parameters.Add(param2)
aCmd.Parameters.Add(param3)
Dim da As New OleDbDataAdapter
da.SelectCommand = aCmd
Dim ds As DataSet
ds = New DataSet("Customers1")
da.Fill(ds, "New Customers1")
...
|
|
|
|
|
Hi, advice on the use of Private Properties required (please!).
In my aplication I have classes which have variables which can be read by but not changed by other classes via Public ReadOnly Properties. Now, should the values of these variables be set within the class using Private WriteOnly properties or is it OK to directly assign to the variable?
Thanks in advance for your time.
|
|
|
|
|
I think it's partly a matter of coding style. If you just assign the value, it's simpler (and a bit more efficient) to use the field directly.
However, if you have (or you're likely going to have) somekind of logic in the assignment, it's better to use a property (or a method). For example, when assigning a value to a field, you raise and event, do some calculation, check the value etc. it would be better to have a property.
|
|
|
|
|
Cool, thanks Mika
|
|
|
|
|
No problem Hopefully others will share their opinions too.
|
|
|
|
|
Due to a recent hard to find problem with this same scenario, I switched to using properties exclusively for setting variable values (per recommendation of Dave K).
It's a couple more lines of code and very minimal time to just break it out. Even if your code for now doesn't have any extra checks/logic before setting the value and it's module/class scope, you could easily expand the property to add checks in the future. It also helps in determining when a variable gets a value that is not expected.
In VB6, you could create and set a global breakpoint to "break" when the variable is set = to the value your looking for. That type of global break point doesn't exist in VB.Net. If your variable is set using a property, then you can indeed easily do this without breakpointing everywhere the variable is being set.
As you mentioned, you can have mix match of scope within the property itself.
Performance wise, unless your doing something off the wall like a trillion loops with reading/setting values, you are not going to have a performance issue; otherwise, you might want to access the variable directly in these rarer cases (like Mike discussed).
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
OK, thanks Jon_Boy. Like Mika suggested, this sounds like a matter of coding style, but I do actually like the idea of using properties to set object wide variables. After all, I use properties to set some variables but then directly assign others, so using properties to set all variables will at least ensure consistency, which I like.
Thanks for your time
|
|
|
|
|
The reason I told him that little trick is because occasionally you run into a problem where a value is set in a class, but you can't find where the value is being set from. Using a private property, you can set a breakpoint in the setter code, then look at the stack trace to see exactly where the value came from.
|
|
|
|
|
I did try to search (albeit quick) for my orig post yesterday, but couldn't find it. oh well...
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Hi I'm stuck on this problem I have with the webbrowser control. I am trying to print a html doc that has been loaded into the control like follows
html.Navigate(New System.Uri(fileName))
html.Show()
html.Width = 800
html.Height = 600
html.Refresh()
and then print it using
html.print
but nothing happens. Does anyone know why
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
Stephen Lintott wrote: but nothing happens. Does anyone know why
Do you have a printer configured?
print() function takes the default page and print settings form the system.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Yes sorry should have said it but I do have a printer configured.
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
try html.Print()
with the parenthesis, also check your default printer...
See the documentation[^] for information about permissions.
|
|
|
|
|
hello to everyone
I'm trying to store an ID of a person from a table which is related to another so I wrote a peace of code that takes the names of persons from that table and expandes them on a combobox but when I click on a Save button it does not take the ID of a person to store it on a table which is related.
Here is my code:
Private Sub frmXhirojare_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ds As New DataSet
Dim conn As SqlConnection = New SqlConnection("Data Source=.;Initial Catalog=dbHyrjaXhirove;Integrated Security=True")
Dim selection As String = "SELECT PartneriID, Emri FROM tblPartneret"
Dim dataadapteri As SqlDataAdapter = New SqlDataAdapter(selection, conn)
dataadapteri.MissingSchemaAction = MissingSchemaAction.AddWithKey
dataadapteri.Fill(ds, "tblXhiro")
ComboBox1.DataSource = ds.Tables("tblXhiro")
ComboBox1.ValueMember = "PartneriID"
ComboBox1.DisplayMember = "Emri"
End Sub
I would be thankful to everyone who takes a minute from his time to explain it to me why when I click to the Save button it does not take the PartneriID in this case and store it on related table.
Qendro
|
|
|
|
|
ComboBox1.Value should contain the person Id.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Could You be more specific and tell me where to write Combobox1.Value because in my code I wrote Combobox1.ValueMember = "PartneriID" which I think is the appropriate thing in this case.My problem is that when I click on the Save button it saves all the values through the parameters exept the PersoniID which is represeted by this combobox.
Thank You for your reply and I would be thankful if You put me in a correct road with this problem.
Qendro
|
|
|
|
|
ValueMember sets where to get the value from. Value is the value that was set. I think you need to do some reading on VB.NET, this is pretty straightforward stuff.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
|
Thanks Mika. But how do I code to insert the new line below Address1 each time?
|
|
|
|
|
For example, loop the array read from the file and insert each element to another array. Also in the loop, check if the string is Address1 and if it is, after insertion to the target array add an extra element for the url (or whatever you wish to add).
If you know the amount of Address1 elements, you can define the target array size before the loop. For example target array length + target array length / 3 (if you always have 3 rows for each person). If you cannot calculate the size beforehand, you can use Array.Resize[^] when needed
|
|
|
|