Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can a textbox be bound to a database or stored procedure?

Status
Not open for further replies.

cmsbuffet

Programmer
Feb 3, 2009
173
CA
Can a textbox be bound to a database or stored procedure? I would like to connect a textbox to a database. More specifically, I would like to pick a value in the textbox and have selected all the rows in the database that have that value in the textbox. What hints can you give me? Thanks.


 
You can't bind a textbox. You will have to get the value from the textbox, create a command object and execute a stored procedure.
 
I think you're mixing up concepts.

if you want to use the textbox to capture a serachable value, then the textbox is not bound to anything. you just get the value from the textbox when the user clicks "search".

the textbox value will eventually be passed to the sql statement and the results returned would be passed back to the presentation layer for display. I say eventually be it's not good practice to have the presentation layer talk directly to data access objects.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Perhaps, I just want to create a search button, a textbox that has an entry searched for, then how do I display the result of search?
 
however you want:) once you get the value from the textbox, you then pass this along until it ends up in an IDbCommand parameter. from there you can execute the command reader and the read the results into a datatable (or custom object). once in the datatable pass this back up to the presentation layer and present.

with webforms you can bind a datatable (because it implements IEnumerable) to a gridview to display tabular data. this is webforms 101 and there are plenty of examples online.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Could you give me an example on how to use IDbCommand and IEnumerable in VB? Thanks.
 
use google.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
For instance,

Code:
 If zipcodeTextBox.Enabled Then
            myValue = myValue.Equals(myValue, SqlCommand("Select ID from zipcodes;"))

            
        End If

Does Enable suit in here? and what can I use instead of SqlCommand? SqlCommnad cannot be used as an expression.
 
The code you have will not query the database. As Jason has stated, use Google, there are MANY examples online.
 
what are you trying to do?
sqlcommand is an object that must be instantiated.
var command = new SqlCommand(...);

myvalue is not a sqlcommand so it will always be false once you instantiate the command.

the command still needs to be executed. at some point you will call command.ExecuteReader(), or ExecuteScalar() or ExecuteNonReader() depending on you're requirements.

you should spend some time learning OOP and how to utilize the .net framework and ado.net (sub set of .net).

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Where do I need to place the code below in Page_Load, so that the GridView and DetailsView will be coordinated with each other?
Code:
DetailsViewZipcodes.PageIndex = GridViewZipcodes.SelectedIndex
 
cmsbuffet, stop and think.
1. understand the tools you are working with. it seems like you are taking shots in the dark at what objects to use or how to use them. if you don't know either. then take the time to learn.
2. the above code has not context, so we cannot say whether it's right or wrong.
3. we are not here to do your work for you. we can guide and assist, but we are not your extended development team.
4. new topics should be new threads. this started with how to bind a text box to a stored proc. now we are reveiwing details and grid views. they are not related.

here is what you need.
1. understand asp.net
2. understand the webform page life cycle. (asp.net and webform are actually 2 distinct archictures. webforms is built on top of asp.net, but asp.net has no knowledge of webforms.)
3. understand how ado.net works. the object involved and how to do CRUD.
4. understand good OOP and SOLID design practices.

this is a very high level list. each can take weeks/months (SOLID and OOP, years) to master. But moving in this direction will give you a skill set that you can use no matter what language, or requirement you are tasked with.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thank you for the advice. I already have watched 8 tutorials in Videos Asp.Net 2.0 for the beginners. It took me 2 days. I am planning to watch more, of course, when I have more time, and I will.

However, there are sometimes little things, that I cannot find on google that help to produce a better code.

For instance, I have never used Console.WriteLine before, what can I use instead so that the text will be displayed not in the console, but in the .aspx page? Or, for instance, I am writing a sub named "A", but I don't know how to call it in Page_Load in script VB, all the parameters that "A" has is a sting, and how can I display the output in .aspx page?

I don't know if my questions were stupid again, it's not for me to judge.
 
there not stupid questions we have to start somewhere when we are learning. personally I don't care for asp.net tutorials as it's all just drag/drop wizards.

I would recommend finding a book on your language of choice. for me it's C# I love "c# via clr". I'm sure there is a vb equivalent.

I would make this recomendation.
1. find a book on your language, there a plenty to choose from.
2. find examples of how ado.net works. connections, commands, transactions, readers, parameters, etc.
3. get a base understanding of asp.net handlers, modules, httpapplication, httpcontext, request, response, etc.
4. understand webforms and the webforms life-cycle. (some refer to it as the asp.net life cycle, my included. but it's specific to webforms, not asp.net) btw: the life-cycle was designed to "help" rich client developers move into a web-based paradigm. I am now of the opinion this was a mistake, but that's just me:)

.net is a rather large framework with all kinds of base functionality. you can use these objects as is, but I find more value is gained by implementing these base objects into my own custom objects.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
What can I substitute with a line console.writeline? Thanks. Is it still ok to ask questions? This one is very small. )))))
 
console.writeline will only work in a console application. You will need to use response.write("text or variable here")
However, it is best to use the debugger to trace through you code to find error and see how the code is exetuting.
 
I found out I can use trace.write or response.write, but I don't know how to display them on .aspx page. That is, how to call them.

Code:
Console.WriteLine("List All Rows:")

            Dim row As DataRow

            For Each row In categories.Rows
                Console.WriteLine("{0}: {1}", row(0), row(1))

            Next
Can become
Code:
 Response.Write("List All Rows:")

            Dim row As DataRow

            For Each row In categories.Rows
                Response.Write("{0}: {1}", row(0), row(1))

            Next
        End Using
But how do I call Response onto .aspx. I need data from Response displayed in a control (gridview) which later has to be connected to a detailsvies or formview on .aspx page.

Where do I start?
 
instead of logging your messages to the aspx (which will require all kinds of if/then or #ifs or add/remove blocks of code for production. integrate a logging framework into your application. this way you can use it both for development and production, and it does not require you to add/remove code just to trace your workflow.

I like log4net, other popular ones are MS enterprise library logging and nlog.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top