|
-
Jan 24th, 2003, 03:39 PM
#1
Thread Starter
Member
My First Class
I have created a class which accepts an sqlstring and an open connection and executes the sql returing an error message if one was thrown. I don't know if I should add a dispose to the class or what else I should add. This is my first class I created, so any suggestions of how I can enhance the code to make it better please let me know. I tested the class and it does what it is suppose too.
Public Class RunSql
Dim Err As SqlException
Sub Execute(ByVal SqlString As String, ByVal MyCnn As SqlConnection)
Dim e As SqlException
Dim myCMD As New SqlCommand(SqlString, MyCnn)
Try
myCMD.ExecuteNonQuery()
Catch e
Err = e
Finally
End Try
End Sub
ReadOnly Property SqlErr() As SqlException
Get
Return Err
End Get
End Property
End Class
Frank
-
Jan 24th, 2003, 04:04 PM
#2
should .Dispose() you SQLCommand object when done with it.
-
Jan 24th, 2003, 04:35 PM
#3
Thread Starter
Member
-
Jan 26th, 2003, 02:16 AM
#4
PowerPoster
You could make your class generic by using interfaces. This way, you can check the type that is passed in and use the correct objects. Just a thought..
-
Jan 27th, 2003, 08:49 AM
#5
Thread Starter
Member
I have also created a class to return a field value .. .executescalar. And I was stuck on how to distinguise between datetime, string, integer, real types being passed in. I will have to investigate how to check the type being passed in.
Thanks.
Frank
-
Jan 27th, 2003, 12:44 PM
#6
Sleep mode
my function will do the job easily . just pass the object you to know its type....
VB Code:
Public Function RetObj(ByVal MyObj As Object)
Dim obj As New Object()
If obj.GetType Is GetType(Object) Then
MessageBox.Show(MyObj.GetType.Name)
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String = "Pirate"
Dim datetim As DateTime
Dim int As Integer
Dim byt As Byte
RetObj(str)
RetObj(datetim)
RetObj(int)
RetObj(byt)
End Sub
-
Jan 27th, 2003, 12:49 PM
#7
Thread Starter
Member
Thanks!
That will get me on the right track.
Frank
-
Jan 27th, 2003, 12:53 PM
#8
Sleep mode
little note , if you passed null string it will throw exception , till now i can't figure how to pass null str . otherwise it's works like charm !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|