Must be getting senile. That should be it. It should also explain why the method shown by unrealweapon wasn't working since deora was using a normal dataadapter instead of the one created in the dataset designer.
Printable View
oh gosh..im little confuse with everything now...this is how i type in my form load...
Code:Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strUsername As String
Dim daLoadEmployee As New OleDb.OleDbDataAdapter
Dim dsCurrentUser As New userDataSet
Dim frmNewLogin As New frmLogin
frmNewLogin.ShowDialog()
Dim cmdLoadEmployee As New OleDb.OleDbCommand("Select ename, hobby, color, MID from employee where MID=?")
daLoadEmployee.SelectCommand.Parameters.Add("@UserName", OleDb.OleDbType.VarChar)
daLoadEmployee.SelectCommand.Parameters("@username").Value = strUsername
daLoadEmployee.Fill(dsCurrentUser.Employee)
'TODO: This line of code loads data into the 'UserDataSet.Employee' table. You can move, or remove it, as needed.
'Me.EmployeeTableAdapter.Fill(Me.UserDataSet.Employee)
txtEmployee.DataBindings.Add("Text", EmployeeBindingSource, "Ename")
txtHobby.DataBindings.Add("Text", EmployeeBindingSource, "Hobby")
txtColor.DataBindings.Add("Text", EmployeeBindingSource, "Color")
txtManager2.DataBindings.Add("Text", EmployeeBindingSource, "MID")
End Sub
but there's an error..
http://img842.imageshack.us/img842/4382/30673586.jpg
im also wondering why is there is no code declaring something to capture the frmLogin.txtManager.text ???
am i doing it right?? :O:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strUsername As String
Dim daLoadEmployee As New OleDb.OleDbDataAdapter
Dim dsCurrentUser As New userDataSet
Dim frmNewLogin As New frmLogin
frmNewLogin.ShowDialog()
strUsername = frmLogin.txtManager.text
Dim cmdLoadEmployee As New OleDb.OleDbCommand("Select ename, hobby, color, MID from employee where MID=?")
daLoadEmployee.SelectCommand.Parameters.Add("@UserName", OleDb.OleDbType.VarChar)
daLoadEmployee.SelectCommand.Parameters("@username").Value = strUsername
daLoadEmployee.Fill(dsCurrentUser.Employee)
'TODO: This line of code loads data into the 'UserDataSet.Employee' table. You can move, or remove it, as needed.
'Me.EmployeeTableAdapter.Fill(Me.UserDataSet.Employee)
txtEmployee.DataBindings.Add("Text", EmployeeBindingSource, "Ename")
txtHobby.DataBindings.Add("Text", EmployeeBindingSource, "Hobby")
txtColor.DataBindings.Add("Text", EmployeeBindingSource, "Color")
txtManager2.DataBindings.Add("Text", EmployeeBindingSource, "MID")
End Sub
Everytime u declare a variable, remember to set it first before using it. the very basics of every programming language. Get and Set vice versa.
in ur ori coding, u declared strUsername, however u did not set it first. therefore, strUsername equals to Nothing/null which will definitely give u a null reference problem or other problem.
to use frmLogin.txtManager.text, txtManager's modified Property MUST be set to Public.
ooo..ok Unreal...there's no error message pop out now...but when i run the program and log into the form..the textboxes can't display those data sweat.gif ......what went wrong?? (i already check my database, there's data inside)
here's the sql statement i type..
http://img823.imageshack.us/img823/9719/aaaabb.jpg
There's current a couple of problems with you existing program. The first is the dataset that you have designed. Try to fix this part first. Follow the steps given by unrealweapon. The difference would be the sql query that should be:
Code:select *
from employee
where mid = ?
This should result in a code with a new method under the EmployeeTableAdapter called FillBy,GetBy(MID). If your sql has an error in this step, you will get FillBy,GetBy() instead. You must make sure that you end up with FillBy,GetBy(MID).
The other is the code that you put into the form load section. At the moment only keep the following part.
Most of your problem comes from using the name of the dataset and dataadapter you have created in your dataset designer as the name of your variable. The dataset and dataadapter you have created are considered as classes not an actual object. You need to declare an object based on the class before you can use them. Example:Code:Dim strUsername As String
Dim daLoadEmployee As New EmployeeTableAdapter
Dim dsCurrentUser As New userDataSet
Dim frmNewLogin As New frmLogin
frmNewLogin.ShowDialog()
strUsername = frmLogin.txtManager.text
daLoadEmployee.FillBy(dsCurrentUser ,strUserName) 'This will not work if your EmployeeDataAdapter is not setup correctly.
'This is needed to make sure that you bindingsource is pointed to the correct datasoutce
EmployeeBindingSource.datasource = dsCurrentUser.Employee
Code:Dim daLoadEmployee As New EmployeeTableAdapter
'No using me.EmployeeTableAdapter
Dim dsCurrentUser As New userDataSet
'No using me.userDataSet
here's what i get after i type in the sql statement..is correct right??
http://img651.imageshack.us/img651/6066/52572430.jpg
but there's a declaration problem in my code if i use
Dim daLoadEmployee As New EmployeeTableAdapter
:ehh:
http://img24.imageshack.us/img24/4326/74518720.jpg
You are nearly there, try this declaration instead:
Code:
Dim daLoadEmployee As New userDataSetTableAdapters.EmployeeTableAdapter
hi @skylerzz...after i change that sentence..then another word has error
http://img28.imageshack.us/img28/2631/79074156.jpg
erm..u mean like this??
Code:daLoadEmployee.FillBy(dsCurrentUser.EmployeeDataTable, strUsername)
cannot le..still got blue line..
i tried like this also cannot
Code:daLoadEmployee.FillBy(Me.UserDataSet.Employee, strUsername)
the yellow message show something like tat... :ehh:
http://img196.imageshack.us/img196/6818/56878002.jpg
oh yes!!..finally!!..thanks very much to skylerzz & leonez for your patient guidance!! respect respect :thumbup1: :thumbup1: :lol:
anyway..duno why after adding the codes...when i log in tat time..the login form will pop up twice only can enter to the frmMain...any idea?
It is possible that you have setup frmLogin as the startup form for your project. Use your main form as the startup form.
There seem to be an error in the code that you are using. You should be using the frmNewLogin that was declared in the main form load event.
Code:
'Wrong one
'strUsername = frmLogin.txtManager.text
'Correct one
strUsername = frmNewLogin.txtmanager.text