Look at this please...!!!!

Apr 3 2008 11:29 AM

hi all again, i need some help with this code, which fills some comboboxes depending on the id, For example if in the Country combobox the Country"Greece" ,which has the id 1, then in the State combobox, all the states of Greece are shown, and show on..

CODE:

Imports System.Data.OleDb

Public Class Teachers

Sub Country_ComboFill()

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\School.mdb"

Dim conn As New OleDbConnection(connString)

 

Dim strSQL As String = "SELECT * FROM Countries"

Dim da As New OleDbDataAdapter(strSQL, conn)

Dim ds As New DataSet

Dim dr As DataRow

da.Fill(ds, "Countries")

For Each dr In ds.Tables("Countries").Rows

cmbCountry.Items.Add(dr.Item("CountryID") & "-" & dr.Item("CountryName"))

Next

conn.Close()

ds.Dispose()

da.Dispose()

End Sub

Sub State_ComboFill(ByVal CountryID As Integer)

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\School.mdb"

Dim conn As New OleDbConnection(connString)

Dim strSQL As String = "SELECT * FROM States Where CountryID=" & CountryID & ""

Dim da As New OleDbDataAdapter(strSQL, conn)

Dim ds As New DataSet

Dim dr As DataRow

da.Fill(ds, "States")

cmbState.Text = ""

cmbState.Items.Clear()

For Each dr In ds.Tables("States").Rows

cmbState.Items.Add(dr.Item("StateID") & "-" & dr.Item("StateName"))

Next

conn.Close()

ds.Dispose()

da.Dispose()

End Sub

Sub Municipality_ComboFill(ByVal StateID As Integer)

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\School.mdb"

Dim conn As New OleDbConnection(connString)

Dim strSQL As String = "SELECT * FROM Municipalities Where StateID='" & StateID & "'"

Dim da As New OleDbDataAdapter(strSQL, conn)

Dim ds As New DataSet

Dim dr As DataRow

da.Fill(ds, "Municipalities")

cmbMunicipality.Text = ""

cmbMunicipality.Items.Clear()

For Each dr In ds.Tables("Municipalities").Rows

cmbState.Items.Add(dr.Item("MunicipalityID") & "-" & dr.Item("MunicipalityName"))

Next

conn.Close()

ds.Dispose()

da.Dispose()

End Sub

Sub Area_ComboFill()

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\School.mdb"

Dim conn As New OleDbConnection(connString)

 

Dim strSQL As String = "SELECT * FROM Areas"

Dim da As New OleDbDataAdapter(strSQL, conn)

Dim ds As New DataSet

da.Fill(ds, "Areas")

cmbArea.DataSource = ds.Tables("Areas")

cmbArea.DisplayMember = "AreaName"

 

End Sub

Sub Teacher()

Dim fname As String = txtFname.Text

Dim lname As String = txtLName.Text

Dim FatName As String = txtFathersName.Text

Dim Country As String = cmbCountry.Text

Dim State As String = cmbState.Text

Dim municipality As String = cmbMunicipality.Text

Dim area As String = cmbArea.Text

Dim zip As String = txtZIP.Text

Dim address As String = txtAddress.Text

Dim addressno As String = txtAddressNo.Text

Dim phone As String = txtPhone.Text

Dim phone2 As String = txtPhone2.Text

Dim email As String = txtEmail.Text

Dim photo As String = txtphoto.Text

Dim day As String = Date.Now.Date

Dim time As String = Date.Now.TimeOfDay.ToString

Dim sex As String = cmbSex.Text

 

Dim con As OleDbConnection

Dim da As New OleDbDataAdapter

con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\School.mdb")

con.Open()

Dim Trans As OleDbTransaction = con.BeginTransaction

Dim command As New OleDbCommand

command.Connection = con

command.Transaction = Trans

command.CommandText = "INSERT INTO Teacher(FirstName, LastName, FathersName, Sex, Country, State, Municipality, Area, Zip, Address, AddressNo, Phone, Phone2, Email, Photograph) values ('" & fname & "','" & lname & "','" & FatName & "','" & sex & "','" & Country & "','" & State & "','" & municipality & "','" & area & "','" & zip & "','" & address & "','" & addressno & "','" & phone & "','" & phone2 & "','" & email & "','" & photo & "')"

Try

da.InsertCommand = command

da.InsertCommand.ExecuteNonQuery()

Trans.Commit()

fname = ""

lname = ""

MessageBox.Show("Saved succesfully", "Adding Student Info Data", MessageBoxButtons.OK, MessageBoxIcon.Information)

Catch ex As Exception

Trans.Rollback()

MessageBox.Show(ex.Message)

Exit Sub

End Try

con.Close()

command.Dispose()

da.Dispose()

Trans.Dispose()

End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

Teacher()

End Sub

Private Sub Teachers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Country_ComboFill()

'State_ComboFill()

'Municipality_ComboFill()

Area_ComboFill()

End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

Me.Close()

End Sub

End Class

THIS IS THE ERROR :

Error 1 Argument not specified for parameter 'CountryID' of 'Public Sub State_ComboFill(CountryID As Integer)'. C:\Documents and Settings\Administrator\Desktop\Projects\School\School\School\Teachers.vb 163 9 School


Answers (1)