TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mohammed Adamu
NA
107
47.9k
VB Application
Nov 26 2015 7:05 PM
Please can some one help to do this right , am trying to in insert the below values into sql server 2008
"ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
there seem nothing wrong with the code either
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Dim MyConnection As Odbc.OdbcConnection = Nothing
Dim MyTransaction As Odbc.OdbcTransaction = Nothing
Try
' create the connection and transaction object
MyConnection = New Odbc.OdbcConnection(My.Settings.GROUP_WORKConnectionString)
MyConnection.Open()
MyTransaction = MyConnection.BeginTransaction
' insert the new recipt
Dim SQL As String = "insert into recipt (reciptdate,recipttotal) values (:0,:1)"
Dim CMD1 As New Odbc.OdbcCommand
CMD1.Connection = MyConnection
CMD1.Transaction = MyTransaction
CMD1.CommandText = SQL
CMD1.Parameters.AddWithValue(":0", Now.ToOADate)
CMD1.Parameters.AddWithValue(":1", TextBox4.Text)
CMD1.ExecuteNonQuery()
CMD1.Dispose()
' get the id for the recipt
SQL = "select max(reciptid) as MAXID from recipt"
Dim CMD2 As New Odbc.OdbcCommand
CMD2.Connection = MyConnection
CMD2.Transaction = MyTransaction
CMD2.CommandText = SQL
Dim ReciptID As Long = CMD2.ExecuteScalar()
CMD2.Dispose()
' insert the details of the recipt
Dim I As Integer
For I = 0 To DGV2.Rows.Count - 1
' get the values
Dim Barcode As String = DGV2.Rows(I).Cells(0).Value
Dim Descript As String = DGV2.Rows(I).Cells(2).Value
Dim BuyPrice As Decimal = DGV2.Rows(I).Cells(3).Value
Dim SellPrice As Decimal = DGV2.Rows(I).Cells(4).Value
Dim ItemCount As Integer = DGV2.Rows(I).Cells(5).Value
' next create a command
Dim CMD3 As New Odbc.OdbcCommand
SQL = "insert into ReciptDetails " & _
"(reciptid,barcode,itemcount,itembuyprice,itemsellprice) " & _
"values " & _
"(:0 ,:1 ,:2 ,:3 ,:4 )"
CMD3.Connection = MyConnection
CMD3.Transaction = MyTransaction
CMD3.CommandText = SQL
CMD3.Parameters.AddWithValue(":0", ReciptID)
CMD3.Parameters.AddWithValue(":1", Barcode)
CMD3.Parameters.AddWithValue(":2", ItemCount)
CMD3.Parameters.AddWithValue(":3", BuyPrice)
CMD3.Parameters.AddWithValue(":4", SellPrice)
CMD3.ExecuteNonQuery()
CMD3.Dispose()
Next
' all well save the changes
MyTransaction.Commit()
' close connection
MyTransaction.Dispose()
MyConnection.Close()
MyConnection.Dispose()
DGV2.Rows.Clear()
TextBox4.Text = ""
Catch ex As Exception
If MyTransaction IsNot Nothing Then
MyTransaction.Rollback()
End If
If MyConnection IsNot Nothing Then
If MyConnection.State = ConnectionState.Open Then
MyConnection.Close()
End If
End If
MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Error")
End Try
End sub
Reply
Answers (
0
)
How do I pass data from child of child form to parent form?
how to put images in SQL database?