Hi there,
I have a code which I insert information inside of SQL Table, it used to work fine with the update and overwriting the information before I decided to input data based on the number of the months that I choose, Now the inserting works perfectly fine but when I want to update the same information that I inserted it doesn't update of it just one of it, the one that I choose.
Here is the code :
Dim startdate As DateTime = DateTimePickerFixCosts1.Value
Dim enddate As DateTime = startdate.AddMonths(txtNumberofMonths.Text)
Do While (startdate <= enddate)
db = New ADODB.Connection
db.ConnectionTimeout = 10
connstr = "Provider = sqloledb;Data Source=#####\SQLEXPRESS;Initial Catalog=Expenses;Trusted_Connection=yes;"
db.ConnectionString = connstr
db.Open()
sqlstr = "Select * from Test_Table where ID = '" & Val(TxtIDFixCosts.Text) & "'"
adoRS = New ADODB.Recordset
adoRS.Open(sqlstr, db, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
If (adoRS.EOF = True) Then
' insert
adoRS.AddNew()
adoRS.Fields("Date").Value = startdat
adoRS.Fields("Department").Value = TxtFixCosts.Text
adoRS.Fields("Description").Value = TxtItemDescFixCosts
adoRS.Fields("Payment").Value = TxtPaymentFixCosts.Text
adoRS.Fields("Price").Value = txtPriceFixCosts.Text
MsgBox("Your Record has been inserted")
adoRS.Update()
Else
If (MsgBox("This item in this date is already inserted " & vbCrLf & "Would you like to overwrite it?", MsgBoxStyle.YesNo, "This Item exist") = vbYes) Then
' overwrite
adoRS.Fields("Date").Value = startdat
adoRS.Fields("Department").Value = TxtFixCosts.Text
adoRS.Fields("Description").Value = TxtItemDescFixCosts.Text
adoRS.Fields("Payment").Value = TxtPaymentFixCosts.Text
adoRS.Fields("Price").Value = txtPriceFixCosts.Text
MsgBox("Your data has been overwrited")
adoRS.Update()
End If
End If
startdate = startdate.AddMonths(1)
adoRS.Close()
db.Close()
Loop
what is that I am doing wrong here, I just cant seem to figure it out.
Thankfully