hi every 1 i am trying to copy stored Employee id and i want to show it on a customer registration form. Basically i want to show which employee severd which customer. below is my code could you plz check or modify it thanks


Dim Con As New SqlConnection
Dim cmd As New SqlCommand
Try
Con.ConnectionString = ("Data Source=SAAD-PC\SQLEXPRESS;Initial Catalog=photoshoot;Integrated Security=True")

Con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT Emp_id FROM staff Where UserName" = "'& login.txtUserName.Text& '"
Dim lrd As SqlDataReader = cmd.ExecuteReader()


RegisterCustomer.txtEmpIDReg.Text = Convert.ToString(lrd("Emp_id"))


Catch ex As Exception
MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records")
Finally
Con.Close()
End Try

Me.Hide()

RegisterCustomer.Show()

RegisterCustomer.txtServerBy.Text = login.txtUserName.Text
End Sub

We would first need to know the name of the columns containing the employee information and the customer information.

I assume the employee table has a customer column or vice-versa.
...or there is a third table containg customer and employee IDs. ( ? )

Change

Dim lrd As SqlDataReader = cmd.ExecuteReader()

RegisterCustomer.txtEmpIDReg.Text = Convert.ToString(lrd("Emp_id"))

to this

dim emp as string = "" 
emp = cmd.ExecuteScalar 
RegisterCustomer.txtEmpIDReg.text = emp

hi , when i replace my existing 2 line e.g
Dim lrd As SqlDataReader = cmd.ExecuteReader()

RegisterCustomer.txtEmpIDReg.Text = Convert.ToString(lrd("Emp_id"))


to

dim emp as string = ""
emp = cmd.ExecuteScalar
RegisterCustomer.txtEmpIDReg.text = emp


its executing the catch part. rather than showing the employee id
There are two tables in my database .First one is for staff table which i am using for employee registration. 2nd table is customer table. In my customer table i used Emp_id as foreign key bcz i assume one employee can server many customer. Now wat i wana do is whoeva employee signs in the system and register a customer.that employee id shoud ve seen in the customer registration form in a textbox called txtEmpIDReg.

plz help.

this is my existing code now.

Dim Con As New SqlConnection
Dim cmd As New SqlCommand
Try
Con.ConnectionString = ("Data Source=SAAD-PC\SQLEXPRESS;Initial Catalog=photoshoot;Integrated Security=True")

Con.Open()
cmd.Connection = Con
cmd.CommandText = "SELECT Emp_id FROM staff Where UserName" = "'& login.txtUserName.Text& '"

Dim emp As String = ""
emp = cmd.ExecuteScalar
RegisterCustomer.txtEmpIDReg.Text = emp
Catch ex As Exception
MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records")
Finally
Con.Close()
End Try
Me.Hide()

RegisterCustomer.Show()

RegisterCustomer.txtServerBy.Text = login.txtUserName.Text
End Sub

Can you please post the error that you got (ex.Message)?

Also is your login form still open?

As a design concept, wouldn't it be easier and faster (less connections in the db) to get the id during login and use that over and over rather than connecting to the db and getting something that should be the same for the duration of this session?

hi , wat i have done now is i dropped the customer dataset on to my form as a detail view. Because the emp_id is foreign key in customer table , the detail view is automatically generating primary key bcz of auto increment,. but employee id , i have to manually insert. wat i wana do here is along with customer id,,the employee who is logged in the system should be shown in the employee field.could you plz gve any idea

Does the user have to login to your app? If they do, then after verifying a valid user get their name and id and store them in global variables. This will make them available for inserts, labels on forms or whatever.

basically its a stand alone system and i want to get the Id number of employee who serves the customer and i want to get that id into the text box. PLz could you provide me the code how to do it. i Can print the user name as it matches in the text box and i can than copy that text into the customer text box field but i wanna get the employee id.thnx

Reply plz..really need to get it done

I really suggest you to read any/some book(s) mate. It would really do good for you. You are constantly asking basic questions, that you should know it easily, if you are coding for at least a couple of months.
No offence, but this is how it is.
We are here to help, not to do all the code instead of you.
You come up with some code, which obviously not working, and with some crappy issue explanation, and then you want from us to save in a god`s way your problem.
This is just not the way we work. Sorry mate.

i really not sure how to do it i have searched books and internet,.couldnt find any thing useful.

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.