473,804 Members | 3,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting an asp:textbox value to an sql parameter

I'm using this sql parameter:

MyCommand.Param eters("@Sport") .value = Server.HtmlEnco de(sport)

to get a value from a textbox control:

<asp:TextBox Name="sport" id="sport" runat="server"> </asp:TextBox>

but i cannot see why I get "Value of type
'System.Web.UI. WebControls.Tex tBox' cannot be converted to 'String'"
error when the value I'm passing is a string.

???
Chumley
Nov 18 '05 #1
4 1380
Try:

MyCommand.Param eters("@Sport") .value = Server.HtmlEnco de(sport.Text)
Chumley the Walrus wrote:
I'm using this sql parameter:

MyCommand.Param eters("@Sport") .value = Server.HtmlEnco de(sport)

to get a value from a textbox control:

<asp:TextBox Name="sport" id="sport" runat="server"> </asp:TextBox>

but i cannot see why I get "Value of type
'System.Web.UI. WebControls.Tex tBox' cannot be converted to 'String'"
error when the value I'm passing is a string.

???
Chumley

Nov 18 '05 #2
<<< but i cannot see why I get "Value of type
'System.Web.UI. WebControls.Tex tBox' cannot be converted to 'String'" error
when the value I'm passing is a string >>>
The reason you get this error is because in the .NET world, objects like
TextBoxes do not have default property values. In the VB6 world, textboxes
had a *default property* (which was text)... meaning that your syntax would
have worked... i.e., you simply specify the object (sport - which is a
textbox), and because you didn't specify the text property (sport.text), the
default property would be retrieved automatically for you. In other words,
VB6 allowed you to get away without specifying the .text property. .NET does
not allow for default properties... you must specify the .text property
explicitly (sport.Text)... and if you're using C#, be sure to get the case
right (sport.text would be different than sport.Text).

HTH

"Chumley the Walrus" <sp*******@yaho o.com> wrote in message
news:1e******** *************** ***@posting.goo gle.com...
I'm using this sql parameter:

MyCommand.Param eters("@Sport") .value = Server.HtmlEnco de(sport)

to get a value from a textbox control:

<asp:TextBox Name="sport" id="sport" runat="server"> </asp:TextBox>

but i cannot see why I get "Value of type
'System.Web.UI. WebControls.Tex tBox' cannot be converted to 'String'"
error when the value I'm passing is a string.

???
Chumley

Nov 18 '05 #3
Hi Chumley,

Probably
MyCommand.Param eters("@Sport") .value = sport.text

(When you have added the parameter before to MyCommand, however I saw that
in another message. It is better to stay in the same thread by the way, than
people can see what you have done already)

I hope this helps?

Cor
Nov 18 '05 #4
> Probably
MyCommand.Param eters("@Sport") .value = sport.text


That again gives me an Object reference not set to an instance of an
object error.
Here is the subroutine I'm using with the click event and such (this
is part of a datagrid display, as for the BindGrid() reference). I'm
able to view the page that displays the datagrid and textboxes/button,
but get the error when i try to add something to the 'sport' and
'articleheader' textboxes:

Sub AddArticle_Clic k(Sender As Object, E As EventArgs)
If (Page.IsValid)

Dim DS As DataSet
Dim MyCommand As SqlCommand

Dim InsertCmd As String = "insert into tblArticles
(sport,articleh eader) values (@Sport, @articleheader) "

MyCommand.Param eters.Add(New SqlParameter("@ Sport",
SqlDbType.VarCh ar, 50))
MyCommand.Param eters("@Sport") .value = sport.Text

MyCommand.Param eters.Add(New SqlParameter("@ articleheader",
SqlDbType.nVarC har, 255))
MyCommand.Param eters("@article header").value =
articleheader.T ext

MyCommand.Conne ction.Open()

' testing from aspalliance stuff
myCommand.Execu teNonQuery()

MyCommand.Conne ction.Close()

End If

BindGrid()
End Sub
Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6492
by: Chumley the Walrus | last post by:
I'm using this sql parameter: MyCommand.Parameters("@Sport").value = Server.HtmlEncode(sport) to get a value from a textbox control: <asp:TextBox Name="sport" id="sport" runat="server"></asp:TextBox> but i cannot see why I get "Value of type 'System.Web.UI.WebControls.TextBox' cannot be converted to 'String'"
6
7902
by: Alex | last post by:
I am a newbie to ASP.NET... What I was trying to do... but yet to succeed in... I am building a customer info database... and on default, I want to display the customer's basic information in the TextBox on Page_Load... but, also allow user to update the information For example: Street1 of the home address
2
17533
by: Matthew Wieder | last post by:
Hi - I'm trying to do client-side validation of the text in a Asp.Net textbox control using javascript. My page has the following: <form id="Form1" method="post" runat="server" onsubmit="return validateName(this);"> and <script language="JavaScript"><!-- function validateName(theForm) {
2
5295
by: Kerri | last post by:
Hi, I have an asp textbox that allows users to enter their password. I have another page that allows a user to edit their user account. On this page I set the text to be the password in the Database. There is a value in my datareader but yet on my
7
2276
by: Jan Hoffman | last post by:
hi @all I have the following element in an ascx-file: <asp:TextBox id="name" runat="server">name</asp:TextBox> The textbox belongs to an application of a telefonebook. I want that if I click into the Textbox *once* that the text "name" is selceted. at the moment I have to double-click.
3
1817
by: Dave | last post by:
I have a button that calls a JavaScript. I need to get the value in an asp:TextBox field to the javascript, either as a parameter or via some mechanism within the JavaScript itself. Any Ideas? TIA, Dave
1
3025
by: Shilpi Chaudhry | last post by:
I have a forloop which I use to create textboxes - but unfortunately all of them have the same ids - I need to assign different ids to these textboxes creeated in the loop so that I can retrieve their corrs values. Anybody?? Code snippet: <% int y = 7; %>
3
2129
by: Patrick | last post by:
Try to put in a TextBox next month's date in format (MMM yyyy). The following does NOT work, why is that? <!--When rendered, the texbox is blank, although the text in the round bracket after the textbox is rendered correctly as (July, 2005)--> <asp:TextBox id="MonthTextBox" runat="server"><%=System.DateTime.Now.ToString("y")%></asp:TextBox> (<%=System.DateTime.Now.ToString("y")%>) <!--Same again. defaultMonth is initialised as early...
0
10560
by: datakix | last post by:
After 16 hours of frustration, I've managed to solve this problem for a project I'm working on. The 'trick' is set EnableViewState="False" for the asp:textbox inside the Repeater control. The problem is that by default the asp:textbox ViewState is True. This means that the textbox value is automatically preserved between postback (saved in the __VIEWSTATE hidden field and restored during a page postback).
11
7765
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and the web server performs a database query and displays the results. All of this works fine. I want the user to be able to press the Enter key while the cursor is still in SearchTextBox and have the SearchButton.Click event fire (thus performing...
0
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.