|
Hi
You can retieve data using a stored procedure in the same way as any other query. There is other (more optimal) ways to retrieve data using a SP, but this is the simplest.
Example:
'---Create Connection
Dim ConnectionString As New SqlClient.SqlConnectionStringBuilder
ConnectionString.DataSource = "localhost" 'ServerName
ConnectionString.InitialCatalog = "MyDataBase" 'DatabaseName
ConnectionString.IntegratedSecurity = True
'Open Connction
Dim Connection As New SqlClient.SqlConnection(ConnectionString.ConnectionString)
Connection.Open()
'---Create/Open Reader
Dim Reader As SqlClient.SqlDataReader
Dim Command As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("MyStoredProcedureName", Connection)
Command.CommandType = CommandType.StoredProcedure 'Optional
Reader = Command.ExecuteReader
While Reader.Read
MsgBox("Field 0 :" & Reader.Item(0).ToString)
MsgBox("Field 1 :" & Reader.Item(1).ToString)
End While
'Close Reader
Reader.Close()
'Close Connection
Connection.Close()
|
|
|
|
|
Thanks
but genarally we r use Exectenonquery() for stred proc
is tere any othre way by using nonquery
Thanks
|
|
|
|
|
ExecuteNonQuery only returns Rows Affected, and populates any Output paramters that was mapped. So this would not work well if you need a resultset.
You could use ExecuteReader/Command, or Use a DataAdapter to retrieve the data.
|
|
|
|
|
|
I need to determine an objects datatype. Using TypeOf works fine when the object has been instantiated (declared as New), but otherwise (when the object is still "nothing"), it does not detect the type.
Any idea how I can detect datatypes of un-instantiated objects?.
|
|
|
|
|
Perhaps you're looking for
var.GetType()
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi, I've already tried that, but it seems that the object must be instantiated before you can use the GetType property.
I need to check for a limited amount of types, so I'm thinking of writing a function and use overloading with the object as parameter, which returns a text/enumrated value, indicating what type it is. Would like to figure out how VB does it behind the scenes though.
|
|
|
|
|
My bad. I was trying it on something that WAS instantiated. I just didn't know it at the time. It looks like you can't, unless you actually have an instance of the object. I've never come acrossed a case where I needed to do anything like this.
Why would you want to do this anyway?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have a centralized function which populates data/executes commands from SQLServer and does some exception handling etc. A parameter which will populated with information such as RowsAffected or DataReaders, is of type "Object".
When calling the function, and a SQLDataReader is used as parameter, is when I have a prob. SQLDataReaders don't have any constructors, so when the function tries to detect what type the object is (Using TypeOF()), it can't (Because its "Nothing").
In the end, I think you're right. I should problably take a different approach.
Thanks for your help in any case.
|
|
|
|
|
Oh man, this gets ugly! A much better approach is to "un-generalize" it. Overloaded functions would work much better. You can still combine the common stuff between different versions of this, like a method to just call a stored proc and return the result set, though.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Overloading solves the problem. Definitely less complicated.
Thanks.
|
|
|
|
|
i want to calculate trigonometric functions and factoriel and x^y
how can i do them?
please help
|
|
|
|
|
Hi
These functions are available inside the .net env, by using the System.Math library.
for example:
dim Angle as double=45
msgbox Math.Tan(Angle)
AND
dim X as double=4
dim Y as double=9
msgbox Math.Pow(X,Y)
|
|
|
|
|
Hi: I am beginner to VB. I defined 5 fields as Boolean in a DB file. I tried to use these fields in VB form as check boxes. My question is, how I can program these 5 fields to take a decision that if 2 or more of theme checked then makes an label to be in deferent colour.
Thank you
kami95
|
|
|
|
|
Maybe something like this:
Dim intCount as Integer = 0<br />
If chkBox1.Checked Then intCount += 1<br />
If chkBox2.Checked Then intCount += 1<br />
If chkBox3.Checked Then intCount += 1<br />
If chkBox4.Checked Then intCount += 1<br />
If chkBox5.Checked Then intCount += 1<br />
<br />
If intCount >= 2 Then lbl.BackColor = Color.Red
|
|
|
|
|
Thank you for your response, I tried the code …I think it will work, but I found a problem to where I put it. I mentioned here that I used this check box as a db fields so I need to refresh the function for each record
Than you in advanced
chkBox1 ID
chkBox2 Driver Licence
chkBox3 Passport No
chkBox4 Birth Certificate
chkBox5 Bank Account
Lb1 Legal -if two or more from above checked
Lb2 Illegal -if less than 2
kami95
|
|
|
|
|
You need to put the code in an event handler that is set to fire whenever any of the five checkboxes has been checked/unchecked. It would look something like this:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged, CheckBox5.CheckedChanged
'Insert the code here
End Sub
Hope this works for you.
|
|
|
|
|
'//IDE: Visual Basic 6.0
'//My method:
'//First you must declare 5 boolean variables,
'//and Connect Database and read your 5 field that value put in 5 boolean variables,like this..
Dim blnID as Boolean
Dim blnDriverLice as Boolean
Dim blnPassNo as Boolean
Dim blnBirthCert as Boolean
Dim blnBankAcct as Boolean
'//Declare a count variable and initialize it
Dim intCheckedCount as integer
intCheckedCount=0
'//Omit db connection code...
'//Provided that your recordset is rs then
'//read field value from db like this
blnID=rs!ID
blnDriverLice=rs!Driver Licence
blnPassNo=rs!Passport No
blnBirthCert=rs!Birth Certificate
blnBankAcct=rs!Bank Account
'//If checked then count
If(blnID) Then intCheckedCount=intCheckedCount+1
If(blnDriverLice) Then intCheckedCount=intCheckedCount+1
If(blnPassNo) Then intCheckedCount=intCheckedCount+1
If(blnBirthCert) Then intCheckedCount=intCheckedCount+1
If(blnBankAcct) Then intCheckedCount=intCheckedCount+1
If(intCheckedCount>=2) Then
Lbl1.BackColor = RGB(255, 0, 0)
Else
Lbl2.BackColor = RGB(255, 255, 0)
End If
'//Finish
-- modified at 22:53 Tuesday 10th October, 2006
|
|
|
|
|
Hi guys,
Iam on deploying my application using excel interop, it worked perfectly in XP but my application intend to run on NT, just found out that NT doesnt support interop dlls.
any other approach for this?
or anyway that i can have the interop dll attached to my application?
tnx in advance.
-::maximus::-
|
|
|
|
|
Hello,
let's say that you have an application with 50+ tables. the most of them are related to each other by their category(eg. customers->cust_categories->cust_types, products->prod_categories->prod_types, etc).
You make a HUGE dataset which have all database contents and use it whenever you need it or you make small datasets even if some of the tables such as "color" for example are exist more than once in these datasets?
thanks in advance,
John
|
|
|
|
|
jlabrou_grc wrote: You make a HUGE dataset which have all database contents and use it whenever you need it or you make small datasets even if some of the tables such as "color" for example are exist more than once in these datasets?
I'll take the third option: I don't use Datasets at all - especially if it is going to be large. DataSets are just not performant on large sets of data - the database is.
|
|
|
|
|
Hi All,
I am developing a windows based application where I am using System.Drawing.Printing.PrintDocument class for displaying report. I have provided design screen where user can change the font size and type. Now I am facing problem while printing. If I change the font size, I am loosing data and total information is not being displayed. Now my question is there any way to find out font width and height of the font object. Specifically not size. I know there is a method to find size. But its of no use to me. I need width and height separately.
Thanks in advance,
Regards,
Krishnaraj
|
|
|
|
|
There is no real height and width of a font object, since most fonts are not monospaced, there is no real character cell you can use to estimate how wide your string is.
There's two ways to go about this. You actually have to use Graphics.MeasureString to get the dimensions of the drawn string to see how big it is in the supplied font. If it's too big, reduce the font size and try again. Keep doing so until the string fits.
Or, I've found a second method that works in limited cases, but it's MUCH quicker if performance is an issue. Instead of drawing the string the exact size you need it, draw it to an offscreen bitmap in a MUCH larger font size, like 96 points. Then draw the bitmap in the control you want, scaled up/down to the size you need. If done properly, it draws nicely, without all the jaggies you get when scaling an image.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
how to set form transperancy in visual basic6.0.if i set .jpg image as form
background how can i get transperancy.if it is in rectangle or any shape else.please send a solution.if i get a solution on this my project is going to be complete.please do me the favour.
mail id: suryapraba_mca@yahoo.com
suryapraba
|
|
|
|
|
Google for "vb6 nonrectangular form[^]" and you'll find the few remaining VB6 examples of this.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|