Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > WinForms/Console Application Design
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the WinForms/Console Application Design 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 June 24th, 2009, 02:59 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default How to declare a parameter with the value of a TextBox1.Text

Hi there i am trying to develop a small windows desktop app, All it needs to do is query a sql2005 database look 4 whatever is in the TextBox and display it in a Grid View.
I am using VS2008 and VB, what i have so far is a Dataset that pulls data from 2 tables then have a stored procedure that :
SELECT Customers.CustomerID, Customers.CompanyName, Products.ProductName
FROM Customers CROSS JOIN
Products
WHERE (Customers.CustomerID = '22')

this works only 4 ID 22, then i did
WHERE (Customers.CustomerID = '" & TextBox1.Text"')did not work

WHERE (Customers.CustomerID = @CustomersId)

now where do i assign the @CustomerID=TextBox1.text??


thanks in advance

Got it it was same as Web form under buytton event.
__________________
bx

Last edited by bex; June 24th, 2009 at 03:24 PM..
 
Old June 25th, 2009, 08:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there..

For @Parameter you have a parameter collection in the command object that execute the SP, where you can add parameters (type, name, value).
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old June 25th, 2009, 08:43 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

Hi i am having truble to call it ?

I have this

Dim
sqlcom AsNew SqlCommand
sqlcom.Connection = SqlConnection
sqlcom.CommandType = CommandType.StoredProcedure
sqlcom.CommandText =
"AccountSelectCommand"
sqlcom.Parameters.Add("@Account", SqlDbType.Char, 8)
sqlcom.Parameters("@Account").Value = TextBox1.Text

But i cant find the connection?
__________________
bx
 
Old June 25th, 2009, 08:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

I don't understand you.. what connection?
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old June 25th, 2009, 09:43 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

ok I have a dataset that searches 2 tables
this is my stored procedure:
ALTER PROCEDURE dbo.AccountSelectCommand
AS
SET NOCOUNT ON;
SELECT table1.CUSN05, table1.CNAM05, table2.SimNet, table2.Cost, table2.Commission
FROM table1 CROSS JOIN
table2
WHERE (table1.CUSN05 = '@Account')

then i have btnSearch and txtSearch

Now how do i call this procedure from the btn Search to disply the matching data in a DataGrid.


__________________
bx
 
Old June 25th, 2009, 11:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

You wrote the code to call it just fine in your last post.. I don't understand your problem...

But, doesn't you need to define the parameters that the Store procedure receive???
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old June 25th, 2009, 12:17 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

it was working fine when i dearched a table now i am searching the dataset

now i fet this error

ExecuteScalar requires an open and available Connection. The connection's current state is closed.

with this code:
Dim sqlcom AsNew SqlCommand
sqlcom.Connection = conn
sqlcom.CommandType = CommandType.StoredProcedure
sqlcom.CommandText =
"AccountSelectCommand"
sqlcom.Parameters.Add("@Account", SqlDbType.Char, 8)
sqlcom.Parameters(
"@Account").Value = txtAccount.Text
Dim Da As SqlDataAdapter = New SqlDataAdapter()
Da.SelectCommand = sqlcom
Dim Ds As DataSet = New DataSet
'Da.Fill(Ds, "Cusn05")
DataGridViewSearch.DataSource = Da


Try
MessageBox.Show(sqlcom.ExecuteScalar.ToString)
Catch Sqlex As SqlException
MessageBox.Show(Sqlex.Message)
EndTry

__________________
bx

Last edited by bex; June 25th, 2009 at 12:23 PM..
 
Old June 25th, 2009, 12:22 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

This is like mad people conversation...

Let's try to order this...

The SP needs to define the parameter...
The code you wrote call the SP just fine...
You have problems connecting to the database???
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old June 25th, 2009, 02:41 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

The SP working with this
Me.NewSelectCommand1TableAdapter.FillBy(Me.TrackingDataSet.NewSelectCommand1)


so where do i add the parameter here?

i created the dataset then SP then went to DataGrid clicked the smart tag and choose datasorce.
This way works without parameter. when i try to hand code the event it gives me th errors.

what is the best approach or is there any book that talks about this?
__________________
bx





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass a control parameter and process a return parameter in sqldatasource jayshankar ASP.NET 2.0 Basics 1 January 1st, 2009 10:18 AM
declare My ajkumar Visual Basic 2005 Basics 0 April 18th, 2007 05:24 AM
Show text from Form3 Textbox1 to Form2 Textbox1 peterasimpson VB How-To 5 December 19th, 2005 06:41 PM
USING PARAMETER INSIDE XSL:TEXT cleytonjordan XSLT 6 July 29th, 2005 07:30 PM





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