Dear friends,
I am a newbie in Visual Basic .NET and hope that your kind assistance will make me to learn it.

The problem has been simplified for the purpose of clarity. I want to make a windows form application that uses an access database. The application will store the list of person's basic details such as name, age and country.

The database contains two related tables ie
person(id, name, age, country_id) and country(id, country_name)

My windows form contains TextBox, DateTimePicker, ComboBox for Name, Age and Country respectively. Now I want to make CRUD operation Programmatically (Not using Visual tools) in the same form with some navigation buttons. Any help and reference link will be highly appreciated.

Thanks for Help in Advance.
Dipendra Gurung, Nepal

Hi gurund,
since you have 2 tables, I suppose you want to check if country_id exists;
you open a connection :
and test if country_id exists in [Country]

dim queryCmd as OleDbCommand
Dim queryStrName, queryStr as String
Dim noCountry as Integer
Dim conn as new System.Data.OleDB.OleDbConnection(...)
queryStrName = "SELECT id FROM Country WHERE country_name = " & chr(34)

queryCmd = new OleDbCommand
With queryCmd
	.Parameter.Clear()
	.commandType = CommandType.text
	.CommandText = queryStr
	.Connection = conn
End with

selected_Country = "Canada"	'ex.
queryStr2 = queryStrName & selected_Country & chr(34)
conn.Open()
if queryCmd.ExecuteScalar() is Nothing then
	' selected_Country does not exist in you table [Country]
else
	noCountry = Convert.ToInt32(queryCmd.ExecuteScalar())
	' Add record to person with
	' anotherCmd.CommandText = "INSERT INTO Persons (id, name, ...) VALUES (@value1, @value2, ...)"
	' anotherCmd.Parameters.AddWithValue("@value1", persID)
	' anotherCmd.Parameters.AddWithValue("@value2", name)
	' anotherCmd.Parameters.AddWithValue("@value3", age)
	' anotherCmd.Parameters.AddWithValue("@value4", noCountry)
	' theStatus = anotherCmd.ExecuteNonQuery
end if

See the idea
jjc, Montreal

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.