Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 1st, 2010, 11:17 AM
Authorized User
 
Join Date: Jun 2003
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Post How Can I Display a Record Value from a Module in a Windows Form TextBox?

Hi,

I am writing this question because I cannot find the answer (thus far) to it in the other threads.

I am a asp.net developer trying to develop a client/sever application in vb.net. Here is my problem, I have a form (frmMain) and a Module (sqlConn).

frmMain contains a textbox (txtDescription) as well as a button (btnConnect) that when selected, calls ConnectToSql() - in Module (sqlConn).

The Module connects to the DB as follows:
Code:
 
PublicSub ConnectToSql()
Conn.ConnectionString = "Server=theServer;Database=theDB;" & _
"User ID=user;Password=pwd;Trusted_Connection=True;"
 
Try
Conn.Open()
' Insert code to process data.
Dim sqlCmd AsNew SqlCommand("SELECT mydesc from tb_desc", Conn)
Dim sqlDa AsNew SqlDataAdapter(sqlCmd)
sqlDa.Fill(dt)
 
If dt.Rows.Count > 0 Then
txtDescription.Text = dt.Rows(0)("my_desc").ToString
EndIf
 
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
 
Finally
Conn.Close()
 
EndTry
 
EndSub
FYI - By the way, this has to be coded (I cannot use databinds) and for those that do not like inline Sql, I will create a Sproc once this is up and running.

I am able to see all of the records from the selected table.

My question is, how do I get the results from the Module to the txtDescription textbox in the Windows form? Your help is greatly appreciated as I am behind the with this time sensitive issue.

Regards!
__________________
SLBIBS

Last edited by slbibs; March 1st, 2010 at 11:24 AM.. Reason: Cannot use databinds





Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to display record number in data entry form markw707 Access 5 August 28th, 2014 12:08 PM
Windows Form won't display after Pressing F5 clay5050 BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 6 March 12th, 2009 08:45 PM
Display the current record in textbox (form) Vassala Access 2 January 25th, 2007 05:05 PM
Addressing form from module MKri VB.NET 2002/2003 Basics 18 December 23rd, 2005 10:22 AM
How to change text in textbox from sub in module jano59 Beginning VB 6 1 September 6th, 2005 12:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.