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

Recommended Answers

All 2 Replies

its just how many entries the table summary has. and checking if the table is empty.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.