|
Hi everybody,This is my first Q in this informative forum.
I'm a new student in VB.NET'so would someone help me please?
I've a project in VB.NET ,where I've SQLData base connected to my project through ADO.NET components, and it's records displayed in Textboxes.
My first question is :
How can I add a button to search specific records determined by two columns in this DB ,and that must be by using one button.
for mor clarification:
when a user want to search the DB,s/he will have two choices according to two column chosen by this user , I and the name of these two columns e.g (patient'sName,patient'sNo)will appear whether on Checkbox or Radibutton and according to any choice the textboxes will represent the search parameters.
My project's code is under the namespace " System.Data.Oledb" .
My second question is :
What is the best technique uesed to make a connection to a DB in Vb.net, the ADO.NET(oledb) provided Data in VB.NET or using a code for each task and command? why?
I would be thankful for you.
|
|
|
|
|
Deema Jack wrote: How can I add a button to search specific records determined by two columns in this DB ,and that must be by using one button.
Add a button. Add a handler. Write a stored proc that does the search based on the two fields. Call the stored proc, using the values of the text boxes, and show the result.
Deema Jack wrote: What is the best technique uesed to make a connection to a DB in Vb.net, the ADO.NET(oledb) provided Data in VB.NET or using a code for each task and command? why?
I'm not sure how you'd 'use a code for each task and command' ? Basically, the best thing to do is to create connections late, release them early. .NET has it's own connection pool. It works best if all your users log into the database with the same user/password ( so permissions are handled within the DB, not at login ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks Christian, but I tried many ways but I failed . Would you tell me please what is the code?
This is my form code:
B1 is to display the first record , B2 for the next one,B3 for the previous one& B4 for the last one. B8 is to make a search by one way,just by (PatientsNo),.So what is the code to make the search by two ways (patientsNo & PatientsName)?
Imports System.Data.OleDb
public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.BindingContext(DataSet11, "PatientsTable").Position =0
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.BindingContext(DataSet11, "PatientsTable").Position=+1
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.BindingContext(DataSet11,
"PatientsTable").Position -= 1
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.BindingContext(DataSet11, "PatientsTable").Position = BindingContext(DataSet11, "PatientsTable").Count - 1
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Dim selcom As New OleDbCommand()
Dim drobj As OleDbDataReader
selcom.Connection = OleDbConnection1
selcom.CommandText = "select* from PatientsTable where(PatientsNo= " & TextBox1.Text & ")"
OleDbConnection1.Open()
drobj = selcom.ExecuteReader
If drobj.Read Then
TextBox1.Text = drobj.GetValue(0)
TextBox2.Text = drobj.GetValue(1)
TextBox3.Text = drobj.GetValue(2)
TextBox4.Text = drobj.GetValue(3)
TextBox5.Text = drobj.GetValue(4)
TextBox6.Text = drobj.GetValue(5)
TextBox7.Text = drobj.GetValue(6)
Else
MsgBox(" The record isn't exist")
End If
OleDbConnection1.Close()
drobj.Close()
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11, "PatientsTable")
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Close()
End Sub
ePrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
|
|
|
|
|
Deema Jack wrote: selcom.CommandText = "select* from PatientsTable where(PatientsNo= " & TextBox1.Text & ")"
Doesn't this work ? You don't need the brackets. Is PatientsNo a text field ? I assume not, but if it is, the string needs to be in quotes.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Okie, I know this will be easy for someone to help with, since I have no clue what I am doing.
I have a DataAdapter linked to a datagrid. I have a textbox that when I type in a number, will bring up all those entries with that number. Everytime I try and edit the Query, I manage to mess it up. Any advice?
I am a Mechanical Engineering intern, but my boss got sent to Germany for a week, so they decided to put me with the Computer guys here, so they have me trying to program a website for them when I am not trained for any of it. hah sorry, little rant.
|
|
|
|
|
It would be helpful to post the working and non working queries. Then someone could provide you better assistance.
|
|
|
|
|
How do you read the Hard Drive or CPU Serial Number in VB 6.0?
Thanks,
Ralph
|
|
|
|
|
|
Hi every body!
First, thank for your help.
I want to build an engine to read HTML Help file (.chm).
It can return topic, content, ... in the .chm file.
I was tried do that with API function HtmlHelp(...) (I found this function in HTML WorkShop), but it only return me the Help View with the .chm file, not any topic, content!
I really need this, please help me
Thanks!
|
|
|
|
|
hi there,
u might take a look on this library
CHM Lib
<< >>
|
|
|
|
|
How can I display text on screen without showing the VB form? The form must be hidden and the text must be transparent but 100% visible. It must not disturb the user. It will be changing text just like the Subliminal Messages in "Self Help Subliminal" software. This needs to be done in VB 6.0 only.
Plz plz help me everybody. I shall be very very greatful to you people.
Accalia
|
|
|
|
|
looks like GDI would be the way to go, but i'm not sure of the exact commands right now. try MSDN-ing GDI there's always something useful there.
|
|
|
|
|
Thank you very much for your help. I would be trying out this but I may need your help a bit as I am not too technical.
|
|
|
|
|
well then again, i may be wrong. the Draw method only allows drawing within the client area.... any help anyone?
|
|
|
|
|
Hi,
how to get the row number of the datagrid when i click on any cell of that row?
i used currentcellchanged event for this ,but i could not get the row number when i click for the first time
|
|
|
|
|
You can use the grid.currentrowindex property
|
|
|
|
|
thanq for your reply,
i'm getting the row number
now i want an event to be fired when i click on any cell/row of the datagrid
|
|
|
|
|
hi,
plz tell me the process to bind a dataset to a Crystal report viewer?
Actually i have to show the data(oracle) in a chart. for that i am using cystal report. There chart and graph option is there.
I am creating one dataset through coding. but i dont know how to bind with that chart.
In the chart wizard binding with dataset option is there but it accepting the dataset which is created with wizard connection not created by coding datset.
Paritosh mahapatra
|
|
|
|
|
how i can run exe (batch)file on 2003 server. My code working fine on 2000 server. but problem occur on when i run this code on 2003 server.
i am using ASPEXE component for running exe file. Component registered successfully. i am login as administator account and give all permission to files folder. but code is not working on 2003 server.
some time it is give permission error and some time run time error.
i already search regarding this issue on many good sites. But not fine any result.
plz give me ur ideas on this code how it is work on 2003 server.
thx in advance.....
arun
rathour
|
|
|
|
|
rathour wrote: but code is not working on 2003 server
can u give us more detail: exception error message, maybe a snippet of code,...
<< >>
|
|
|
|
|
I have a simple For..Next loop in which I declare an integer variable for use in the rest of the loop. I would expect the variable to be re-declared on every iteration, but this isn't happening - it keeps its value throughout all repetitions of the loop. Can anybody explain why this happens? Does the compiler optimise the looped declaration into one? Why would it not at least re-initialise the variable? If this is intended behaviour, does that mean it is safe to declare loop counters/exit flags within the loop body and have it behave as a method variable?
Thanks,
Jon
|
|
|
|
|
You didn't say if you were using VB6 or .NET but for .NET MSDN isn't terribly clear in their explaination; but the relevant part is: "If you declare a variable inside a block, and if you enter that block several times during the lifetime of the procedure, you should initialize the variable to avoid unexpected values. "
See http://msdn2.microsoft.com/en-us/library/bybkyxaz[^]
|
|
|
|
|
Thanks for that Richard, it is VB.NET that I'm using. Interesting behaviour, not what I would have expected, useful to know though! Cheers
Jon
|
|
|
|
|
Hi All,
I have a function which will format the numbers that are returned from a variable. That is, if my Resistance is 0.0189015 then it will return 0.018, and if its 0.000065 it should return 0.00006 instead of a zero.
Here is the function
======================================================================
Private Function FormatResistance(ByVal Resistance As Double) As Double
Dim PositionCount As Int16
Dim ResistanceCheck As String
Dim ResistanceString As String
Dim Resistancelength As Int16
ResistanceString = Resistance
'CStr(Resistance)
Resistancelength = ResistanceString.Length
For PositionCount = 3 To Resistancelength '' not worried if resistance is 0.xx so start in 3rd position and checking till the sixth place
If Mid(Resistance, PositionCount, 1) = 0 Then
ResistanceCheck += Mid(Resistance, PositionCount, 1) ' THis is done becos Materials like BRass has almost 0 resistance and if not formatted
'will not add to the material list because of the Isvalid Function check
End If
Next
If ResistanceCheck = "000" Then
Resistance = Format(Resistance, "0.0000")
Else
Resistance = Format(Resistance, "0.000")
End If
Return Resistance
End Function
The problem is, for the Resistance value 0.0000625 the string converted is 6.25E something.SO it fails. Any better idea to handle this ?
Or is there a simpler way of doing this ? Please help
Thanks
|
|
|
|
|
The simplest way is to just convert the incoming number from a numeric value to a string:
Private Function FormatResistance(ByVal Value As Double) As String
Dim psTemp As String
If Value = 0.0# Then
FormatResistance = "0"
Else
'convert double value to string
psTemp = Format(Value, "#0.000000")
If psTemp.Substring(psTemp.IndexOf(".") + 1, 3) = "000" Then
FormatResistance = psTemp.Substring(0, psTemp.IndexOf(".") + 6)
Else
FormatResistance = psTemp.Substring(0, psTemp.IndexOf(".") + 4)
End If
End If
End Function
Note that this function does not do any rounding to anything, it just truncates the number based on the examples you gave.
-- modified at 12:39 Tuesday 18th October, 2005
|
|
|
|