How to add a value to a parameter

  • Thread starter Thread starter MikeD
  • Start date Start date
M

MikeD

Ok,

How do I assign a value to a parameter? I would like to assign the text of a
web control to a parameter for addition into a database. I currently create
the parameter in the code-behind as:

Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@strText",
System.Data.SqlDbType.VarChar, 500, "strText"))

I've tried:

Me.SqlUpdateCommand1.Parameters("@strText").Value = Me.strField.Text

.... but it keeps on coming back claiming that strField is not a member
within the class. I've had to manually create strField as it's contained
within a Repeater web data control, so do I also need to some how reference
it in the code behind?

Any thoughts appreciated,

<M>ike
 
Hi Mike,

The left part is right while the right part is causing you problems?
Is there a strField declared somewhere?
 
MikeD said:
How do I assign a value to a parameter? I would like to assign the text of a
web control to a parameter for addition into a database. I currently create
the parameter in the code-behind as:

Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@strText",
System.Data.SqlDbType.VarChar, 500, "strText"))

I've tried:

Me.SqlUpdateCommand1.Parameters("@strText").Value = Me.strField.Text

... but it keeps on coming back claiming that strField is not a member
within the class. I've had to manually create strField as it's contained
within a Repeater web data control, so do I also need to some how reference
it in the code behind?

That's not a problem of the parameter (the left hand side) it's a
problem of fetching the value (the right hand side). Not sure what you
mean by "manually create strField" though...
 
Thanks for your replies so far.

The strField was created by hand as an asp control within the code for the
page. I basically added a line similar to <asp:TextBox id="strField"
RunAt="server Text='<%# DataBinder.Eval(Container.DataItem, "ID")%>' /> into
the <ItemTemplate> section of the repeater control. As I'm using a code
behind I would expect (via VS) the code behind to define the control to
enable its use, but it doesn't. I've tried manually entering the definition
into the code behind but it doesn't seem to associate this with the control
on the form as when I test it's value during runtime it returns 'Nothing'.

I'm getting the impression that a Repeater can not be used for data updates,
perhaps as it's part of the controls class rather than the page class?

If you need more info then please let me know.

<M>ike
 
Back
Top