Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2005 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 November 12th, 2008, 09:26 AM
Authorized User
 
Join Date: Sep 2007
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to read data from textbox

hi to all out there.

I want to know that how i insert text box values into database.mean same whatever he write .i have to insert entered first name and last name into database. first name and lastname are content entered by use

this is what i did...........

Dim Str As String = "INSERT INTO tablename (username, password) Values(Text1Box1.text,textbox2.text)"

please tell where i am going wrong

 
Old November 12th, 2008, 09:45 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

When Str is passed to the database it is passed, literally, as:

INSERT INTO tablename (username, password) Values(Text1Box1.text,textbox2.text)

To correct this you will want to do something like this:
Dim Str As String = "INSERT INTO tablename (username, password) Values('" & Text1Box1.text & "','" & textbox2.text &"')"

Also, I would consider using some sort of parametertized query (such as a stored procedure) since this type of dynamic SQL leaves your application wide open for SQL Injection.

hth.
-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old November 12th, 2008, 11:49 AM
Authorized User
 
Join Date: Sep 2007
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can you make me understand why we did so mean only this one
('" & Text1Box1.text & "','" & textbox2.text &"')"

waiting for reply

 
Old November 12th, 2008, 12:08 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm. It is the basic concept of string concatenation; consider the following:

'For the purposes below, assume the Text property of TextBox1 contains the value Hello
Dim someString as String = TextBox1.Text
Dim someString2 as String = "TextBox1.Text"
Dim someString3 as String = someString & " " & someString2

Console.WriteLine(someString) 'Outputs: Hello
Console.WriteLine(someString2) 'Outputs TextBox1.Text
Console.WriteLine(someString3) 'Outputs Hello TextBox1.Text

So, in your example:
Dim Str As String = "INSERT INTO tablename (username, password) Values(Text1Box1.text,textbox2.text)"

The string INSERT INTO tablename (username, password) Values(Text1Box1.text,textbox2.text) is passed to the database because you have defined it as a string literal (everything is wrapped in " ") to actually appened your values to the string you need to use the Concatenate operator (&) as I outlined in my previous post.

The reason for the ' that directly preceed and follow " is because that is how most databases interpet string values. If you change my code to:

Dim Str As String = "INSERT INTO tablename (username, password) Values(" & Text1Box1.text & "," & textbox2.text &")"

A string that looks something like the following will be passed in:
INSERT INTO tablename (username, password) Values(SomeUsername, SomePassword)

Which is obviously an error. My original code will pass a sting into your database that looks like this:
INSERT INTO tablename (username, password) Values('SomeUsername', 'SomePassword') which is valid.

Does that make sense?

hth.
Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old November 12th, 2008, 02:59 PM
Authorized User
 
Join Date: Sep 2007
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks allot for explaining.

once again thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Read from data grid watashi C# 2005 2 July 23rd, 2007 03:12 AM
Read data from USB san2308 General .NET 0 September 25th, 2006 08:02 AM
I can't read 1 line at a time from a textbox peterasimpson VB How-To 3 August 18th, 2006 11:45 AM
Read IE Data arindambarman .NET Framework 1.x 0 April 6th, 2006 04:45 AM
read data into a TEXTBOX cuwark BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 10 January 12th, 2004 04:59 PM





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