We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,301 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to Retreive the data from Text box in VB.NET

Hi,I need to retrieve the data for Employee details After entering Empno in a 1st text box.I hope it's Simple but i'm Intermediate level in VB.net,Please help ASAP

This is My Coding for VB.NET

Private Sub View_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    con.Open()
    cmd = New SqlCommand("regd_regdetail_Empid", con)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.AddWithValue("@Empid", TxtEmpID.Text.Trim.ToString)
    dr = cmd.ExecuteReader()
    If dr.HasRows Then
        If dr.Read Then
            Label1.Text = dr.GetString(0)
            Label2.Text = dr.GetString(1)
            Label3.Text = dr.GetString(2)
            Label4.Text = dr.GetString(3)
            Label5.Text = dr.GetString(4)
            Label6.Text = dr.GetString(5)

        End If
    End If
    con.Close()
5
Contributors
10
Replies
1 Day
Discussion Span
2 Months Ago
Last Updated
38
Views
pearl.kumar1
Light Poster
44 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Hi,
Instead of cmd.Parameters.AddWithValue("@Empid", TxtEmpID.Text.Trim.ToString) I think you meant cmd.Parameters.AddWithValue("@Empid", Trim(TxtEmpID.Text))

You may also want to check that there is actually a value in the textbox first.

G_Waddell
Practically a Master Poster
619 posts since Nov 2009
Reputation Points: 107
Solved Threads: 93
Skill Endorsements: 5

Hi to all,This is the error rise::"Unable to cast object of type 'System.Int32' to type 'System.String'".

pearl.kumar1
Light Poster
44 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Hi,

Try this then:
cmd.Parameters.AddWithValue("@Empid", Cint(Trim(TxtEmpID.Text)))

G_Waddell
Practically a Master Poster
619 posts since Nov 2009
Reputation Points: 107
Solved Threads: 93
Skill Endorsements: 5

Thanks Waddell,

       I changed the Expression As per your suggestion.But,Same problem was occured..
       InvalidCast Exception was unhandled "Unable to cast object of type 'System.Int32' to type 'System.String'."
pearl.kumar1
Light Poster
44 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
        If not String.IsNullOrEmpty(TxtEmpID.Text) Then
            cmd.Parameters.AddWithValue("@Empid", Integer.Parse(Trim(TxtEmpID.Text)))
        End If
xerohomicide
Newbie Poster
20 posts since Nov 2012
Reputation Points: 0
Solved Threads: 7
Skill Endorsements: 0

Hi to all,This is the error rise::"Unable to cast object of type 'System.Int32' to type 'System.String'".

I suspect that the error is occuring in one of the dr.GetString(#) statements.

Try. dr.Item(#).ToString() instead.

Substitute the actual integer for "#" in the above statements.

TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418
Solved Threads: 148
Skill Endorsements: 13

It would also help if you tell us on what line the error occurs.

Reverend Jim
Carpe per diem
Moderator
3,612 posts since Aug 2010
Reputation Points: 563
Solved Threads: 451
Skill Endorsements: 32

Thank you so much TnTinMN,

 It will work!,
 But the alignment was changed "In a above label they display  the Textbox result.
 I hope i'll Solve this issue..

Thanks again to all Suggest my issue..

pearl.kumar1
Light Poster
44 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Hi to all once again..
I resolve my above issue(I change a call from test box,Instead of textbox,i call from label--that's why the results are displayed from above the label)..
But the actual problem is in the same module.I need to get a result from barcode print..
This is the first time i can use barcode..anyone can suggest how to use coding () in VB.Net..
Private Sub Button3_Click(print_click)(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

pearl.kumar1
Light Poster
44 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Actual VB6 Coding for the same module is..

Private Sub BTNPRINT_Click()
Dim cur_dat_tim As String
Dim copy As Integer
copy = txtcopy.Text
ipid = txtempid.Text
patient = txtemployeename.Text
age = txtage.Text
sex = txtsex.Text
doctor = txtdepartmentname.Text

SQL = "regd_regdetail_ipid " & txtempid.Text & " "
If rs.State Then rs.Close
rs.Open SQL, DBC, adOpenDynamic, adLockOptimistic

Open "lpt1:" For Output As #1
Print #1, "^Q25,1"
Print #1, "^W45"
Print #1, "^H10"
Print #1, "^P1"
Print #1, "^S4"
Print #1, "^AT"
Print #1, "^C1"
Print #1, "^R0"
Print #1, "~Q+0"
Print #1, "^O0"
Print #1, "^D0"
Print #1, "^E10"
Print #1, "~R200"
Print #1, "^L"
Print #1, "Dy2 -Me - dd"
Print #1, "Th: m: s"

Print #1, "AB,-95,0,2,2,0,0," & Employee
Print #1, "AB,-95,40,1,2,0,0,AGE:"
Print #1, "AB,-35,40,1,2,0,0," & age
Print #1, "AB,-95,80,1,2,0,0,SEX:"
Print #1, "AB,-35,80,1,2,0,0," & sex
Print #1, "AB,-95,120,1,2,0,0,empID:"
Print #1, "AB,35,120,1,2,0,0," & empid

'Print #1, "BA,200,120,3,7,48,0,0,4321"
Print #1, "AB,-95,0,2,2,0,0," & patient
Print #1, "AB,-95,40,1,2,0,0,AGE:"
Print #1, "AB,-35,40,1,2,0,0," & age
Print #1, "AB,-95,80,1,2,0,0,SEX:"
Print #1, "AB,-35,80,1,2,0,0," & sex
Print #1, "AB,-95,120,1,2,0,0,empid:"
Print #1, "AB,35,120,1,2,0,0," & empid
'Print #1, "BA,200,120,3,7,48,0,0,4321"
Print #1, "BA,130,120,3,7,50,0,0," & empid & ""
Print #1, "E"


Next

Close #1

MsgBox "Printed", vbInformation, "REGISTRATION"
Call CLEAR_Click
txtIPid.SetFocus

End Sub

I need to convert it from VB.net or please Suggest in the way of coding or Any referral Websites..

pearl.kumar1
Light Poster
44 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0966 seconds using 2.76MB