473,791 Members | 3,360 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
Jul 21 '05 #1
4 6491
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

Jul 21 '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

Jul 21 '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
Jul 21 '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
Jul 21 '05 #5

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

Similar topics

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
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
4
1376
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'"
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
1815
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
10556
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
7764
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
9517
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10156
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
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
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...
0
5435
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
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
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.