0

hi, the below coding of inserting data into database MS Access. So , may i ask what is the meaning for the coding i bold. Why the maxrow>0 , the message will come out? thanks.

con.Open()

sql = "SELECT * FROM summary WHERE line = '" & cbLine.Text & "' AND plants = '" & cbPlant.Text & "' AND dates = #" & dtp.Value & " #"
            
da = New OleDb.OleDbDataAdapter(sql, con)
 da.Fill(ds, "summary")


[B]maxrow = ds.Tables("summary").Rows.Count[/B]

If [B]maxrow > 0 [/B]Then

MsgBox(cbLine.Text & " #" & dtp.Value & " #" & cbPlant.Text & "# already exist")

 Else

 Try


Dim addUser As String = "INSERT INTO summary (line, plants, dates,PartID, PartMD) VALUES ( '" & cbLine.Text.ToUpper & "','" & cbPlant.Text.ToUpper & "', #" & dtp.Value & "#, '" & p1.Text & "', '" & p2.Text & "')"

Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(addUser, con)
cmd.ExecuteNonQuery()

MsgBox("Data have been save.")

Catch ex As Exception
MsgBox(ex.Message.ToString, , "Addition Error")

End Try

End If
con.Close()
End If
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Piya27
1

maxrow = ds.Tables("summary").Rows.Count
'counts the number of rows in the Table 'Summary'.

If maxrow > 0 Then
'CHECKS whether there is atleast one row in the table.(ie., >0)

Basically checks whether Summary table is emplty or not.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.