I'm hope that can understand me.. my english isn't good...
I'm modify the sample in VB2005, to use with a SQL Server Express database.
Firstly, I made a table named 'enroll' in SQL Server, and I agree 2 fields exactly like Access DB example, ID and template. The field "ID" is Int datatype with the property "Is Identity" to Yes value (to simulate an autoincrement field), and the "template" field is Image datatype (in this point I'm not be sure..)
Then, I modify all OleDB objects to SQLClient objects. I think that the conection to DB works fine, because I don't receive any error message..
Well, when I press the buttom "Enroll" of the sample in runtime, the app stoped in this part of code:
' Add template to database. Returns added template ID.
Public Function AddTemplate(ByRef template As TTemplate) As Long
Dim da As New SqlDataAdapter("select * from enroll", connection)
' Create SQL command containing ? parameter for BLOB.
da.InsertCommand = New SqlCommand("INSERT INTO enroll (template) Values(?)", connection)
da.InsertCommand.CommandType = CommandType.Text
da.InsertCommand.Parameters.Add("@template", SqlDbType.Image, template.Size, "template")
' Open connection
connection.Open()
' Fill DataSet.
Dim enroll As DataSet = New DataSet
da.Fill(enroll, "enroll")
' Add a new row.
' Create parameter for ? contained in the SQL statement.
Dim newRow As DataRow = enroll.Tables("enroll").NewRow()
newRow("template") = template.tpt
enroll.Tables("enroll").Rows.Add(newRow)
' Include an event to fill in the Autonumber value.
AddHandler da.RowUpdated, New SqlRowUpdatedEventHandler(AddressOf OnRowUpdated)
' Update DataSet.
da.Update(enroll, "enroll")
connection.Close()
' return ID
'Return 1
Return newRow("ID")
End Function
' Event procedure for OnRowUpdated
Private Sub OnRowUpdated(ByVal sender As Object, ByVal args As SqlRowUpdatedEventArgs)
' Include a variable and a command to retrieve identity value
' from Access database.
Dim newID As Integer = 0
Dim idCMD As SqlCommand = New SqlCommand("SELECT @@IDENTITY", connection)
If args.StatementType = StatementType.Insert Then
' Retrieve identity value and store it in column
newID = CInt(idCMD.ExecuteScalar())
args.Row("ID") = newID
End If
End Sub
can anyone tell me what I do wrong?
Thanks in advance
Euclides Chavez