Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Thursday, March 29, 2012

Pass NULL To Stored Procedure

How do I pass a NULL value to a field while inserting records in a SQL
Server 2005 DB table using a stored procedure? I tried the following
but it inserts an empty string & not a NULL value:
ALTER PROCEDURE dbo.Purchase
@dotnet.itags.org.UserID int,
@dotnet.itags.org.Total decimal,
@dotnet.itags.org.Address varchar(250) = NULL,
@dotnet.itags.org.Country varchar(50) = NULL
AS
INSERT INTO Order (UserID, Address, Country, Total) VALUES (@dotnet.itags.org.UserID,
@dotnet.itags.org.Address, @dotnet.itags.org.Country, @dotnet.itags.org.Total)
I am invoking the above SP with this code in a class file:
Public Class Cart
Public Sub PlaceOrder(ByVal UserID As Integer, ByVal Total As
Double, ByVal Address As String, ByVal Country As String)
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
sqlConn = New SqlConnection("....")
sqlCmd = New SqlCommand("Purchase", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
With sqlCmd
.Parameters.Add("@dotnet.itags.org.UserID", SqlDbType.Int).Value = UserID
.Parameters.Add("@dotnet.itags.org.Total", SqlDbType.Decimal).Value = Total
.Parameters.Add("@dotnet.itags.org.Address", SqlDbType.VarChar, 250).Value =
Address
.Parameters.Add("@dotnet.itags.org.Country", SqlDbType.VarChar, 50).Value =
Country
End With
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlConn.Close()
End Sub
End Class
Using vbc, I compiled the above into a DLL named Cart.dll.
This is the ASPX code (if no values are supplied for the variables
'strAddress' & 'strCountry', those records should be inserted as NULLs
in the DB table):
Sub Submit_Click(....)
Dim boCart As Cart
boCart = New Cart
If (strAddress = "") Then
strAddress = DBNull.Value.ToString
End If
If (strCountry = "") Then
strCountry = DBNull.Value.ToString
End If
boCart.PlaceOrder(iUserID, dblTotal, strAddress, strCountry)
End Sub<rn5a@.rediffmail.com> wrote in message
news:1160169983.937789.306620@.k70g2000cwa.googlegroups.com...

> How do I pass a NULL value to a field while inserting records in a SQL
> Server 2005 DB table using a stored procedure? I tried the following
> but it inserts an empty string & not a NULL value:
.Parameters.Add("@.Address", SqlDbType.VarChar, 250).Value = DbNull.Value
Plus what Mark mention
I think you can set your instance to Nothing
like:
address = nothing;
but if you your object is value type, you have to use the way Mark Mentioned
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"rn5a@.rediffmail.com" wrote:

> How do I pass a NULL value to a field while inserting records in a SQL
> Server 2005 DB table using a stored procedure? I tried the following
> but it inserts an empty string & not a NULL value:
> ALTER PROCEDURE dbo.Purchase
> @.UserID int,
> @.Total decimal,
> @.Address varchar(250) = NULL,
> @.Country varchar(50) = NULL
> AS
> INSERT INTO Order (UserID, Address, Country, Total) VALUES (@.UserID,
> @.Address, @.Country, @.Total)
> I am invoking the above SP with this code in a class file:
> Public Class Cart
> Public Sub PlaceOrder(ByVal UserID As Integer, ByVal Total As
> Double, ByVal Address As String, ByVal Country As String)
> Dim sqlConn As SqlConnection
> Dim sqlCmd As SqlCommand
> sqlConn = New SqlConnection("....")
> sqlCmd = New SqlCommand("Purchase", sqlConn)
> sqlCmd.CommandType = CommandType.StoredProcedure
> With sqlCmd
> .Parameters.Add("@.UserID", SqlDbType.Int).Value = UserID
> .Parameters.Add("@.Total", SqlDbType.Decimal).Value = Total
> .Parameters.Add("@.Address", SqlDbType.VarChar, 250).Value =
> Address
> .Parameters.Add("@.Country", SqlDbType.VarChar, 50).Value =
> Country
> End With
> sqlConn.Open()
> sqlCmd.ExecuteNonQuery()
> sqlConn.Close()
> End Sub
> End Class
> Using vbc, I compiled the above into a DLL named Cart.dll.
> This is the ASPX code (if no values are supplied for the variables
> 'strAddress' & 'strCountry', those records should be inserted as NULLs
> in the DB table):
> Sub Submit_Click(....)
> Dim boCart As Cart
> boCart = New Cart
> If (strAddress = "") Then
> strAddress = DBNull.Value.ToString
> End If
> If (strCountry = "") Then
> strCountry = DBNull.Value.ToString
> End If
> boCart.PlaceOrder(iUserID, dblTotal, strAddress, strCountry)
> End Sub
>

Pass NULL To Stored Procedure

How do I pass a NULL value to a field while inserting records in a SQL
Server 2005 DB table using a stored procedure? I tried the following
but it inserts an empty string & not a NULL value:

ALTER PROCEDURE dbo.Purchase
@dotnet.itags.org.UserID int,
@dotnet.itags.org.Total decimal,
@dotnet.itags.org.Address varchar(250) = NULL,
@dotnet.itags.org.Country varchar(50) = NULL
AS

INSERT INTO Order (UserID, Address, Country, Total) VALUES (@dotnet.itags.org.UserID,
@dotnet.itags.org.Address, @dotnet.itags.org.Country, @dotnet.itags.org.Total)

I am invoking the above SP with this code in a class file:

Public Class Cart
Public Sub PlaceOrder(ByVal UserID As Integer, ByVal Total As
Double, ByVal Address As String, ByVal Country As String)
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand

sqlConn = New SqlConnection("....")
sqlCmd = New SqlCommand("Purchase", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure

With sqlCmd
.Parameters.Add("@dotnet.itags.org.UserID", SqlDbType.Int).Value = UserID
.Parameters.Add("@dotnet.itags.org.Total", SqlDbType.Decimal).Value = Total
.Parameters.Add("@dotnet.itags.org.Address", SqlDbType.VarChar, 250).Value =
Address
.Parameters.Add("@dotnet.itags.org.Country", SqlDbType.VarChar, 50).Value =
Country
End With

sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlConn.Close()
End Sub
End Class

Using vbc, I compiled the above into a DLL named Cart.dll.

This is the ASPX code (if no values are supplied for the variables
'strAddress' & 'strCountry', those records should be inserted as NULLs
in the DB table):

Sub Submit_Click(....)
Dim boCart As Cart
boCart = New Cart

If (strAddress = "") Then
strAddress = DBNull.Value.ToString
End If

If (strCountry = "") Then
strCountry = DBNull.Value.ToString
End If

boCart.PlaceOrder(iUserID, dblTotal, strAddress, strCountry)
End Sub<rn5a@.rediffmail.comwrote in message
news:1160169983.937789.306620@.k70g2000cwa.googlegr oups.com...

Quote:

Originally Posted by

How do I pass a NULL value to a field while inserting records in a SQL
Server 2005 DB table using a stored procedure? I tried the following
but it inserts an empty string & not a NULL value:


..Parameters.Add("@.Address", SqlDbType.VarChar, 250).Value = DbNull.Value
Plus what Mark mention
I think you can set your instance to Nothing
like:
address = nothing;
but if you your object is value type, you have to use the way Mark Mentioned
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications

"rn5a@.rediffmail.com" wrote:

Quote:

Originally Posted by

How do I pass a NULL value to a field while inserting records in a SQL
Server 2005 DB table using a stored procedure? I tried the following
but it inserts an empty string & not a NULL value:
>
ALTER PROCEDURE dbo.Purchase
@.UserID int,
@.Total decimal,
@.Address varchar(250) = NULL,
@.Country varchar(50) = NULL
AS
>
INSERT INTO Order (UserID, Address, Country, Total) VALUES (@.UserID,
@.Address, @.Country, @.Total)
>
I am invoking the above SP with this code in a class file:
>
Public Class Cart
Public Sub PlaceOrder(ByVal UserID As Integer, ByVal Total As
Double, ByVal Address As String, ByVal Country As String)
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
>
sqlConn = New SqlConnection("....")
sqlCmd = New SqlCommand("Purchase", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
>
With sqlCmd
.Parameters.Add("@.UserID", SqlDbType.Int).Value = UserID
.Parameters.Add("@.Total", SqlDbType.Decimal).Value = Total
.Parameters.Add("@.Address", SqlDbType.VarChar, 250).Value =
Address
.Parameters.Add("@.Country", SqlDbType.VarChar, 50).Value =
Country
End With
>
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlConn.Close()
End Sub
End Class
>
Using vbc, I compiled the above into a DLL named Cart.dll.
>
This is the ASPX code (if no values are supplied for the variables
'strAddress' & 'strCountry', those records should be inserted as NULLs
in the DB table):
>
Sub Submit_Click(....)
Dim boCart As Cart
boCart = New Cart
>
If (strAddress = "") Then
strAddress = DBNull.Value.ToString
End If
>
If (strCountry = "") Then
strCountry = DBNull.Value.ToString
End If
>
boCart.PlaceOrder(iUserID, dblTotal, strAddress, strCountry)
End Sub
>
>

Monday, March 26, 2012

Pass UserID in hidden field

I am trying to pass the UserID from a session variable into a new record.
I have a hidden textbox with the userID session in it, but the UserID field is int,4
and the textbox only pases text (I think). So I get an input string error.
am I doing this right?
All help apreciated.
Thanks,
JBIf you've got in in session, you shouldn't need to pass it in from the hidden field.

Either way:

Convert.ToInt32(Session.Item("UserID"))

or

Convert.ToInt32(hiddedTextBox.Text)

Regards,

Xander
Thanks Xanderno,
I've been at this all afternoon with no luck.
I get "input string was not in a correct format"

The parameter code is

myCommand.Parameters.Add(New SqlParameter("@.MemberID", SqlDbType.Int, 4))
myCommand.Parameters("@.MemberID").Value = Convert.ToInt32(UserID)

and the hidden text box is

<asp:TextBox id="UserID" runat="server" text='<% session(UserID")%>' Visible="False"
The database types are correct - any ideas?

Much appreciated,
JB
That means (likely) that UserID is blank. Which, (Ah ha!) looking at your code, it would be.

First, he session variable needs to be written to the html in order to appear in textbox or hidden field.
You could do this with either the full Response.Write: Response.Write(Session.Item("UserID"))
Or with the shorthand equals sign: =Session.Item("UserID")

Beyond that, since you're using an ASP.Net TextBox, with the visibility property set to false,
even if the session variable *was* being response.written, it still wouldn't work, because that textbox wouldn't be sent to the browser!

So, let's try something like this instead:

<input id="UserID" type="hidden" value="<% =Session.Item("UserID") %>" /
And that should fix you up.

Xander
Thanks Xander,

I'm getting closer but it now passes a "0" to the DB
If I use 'input' with an id of UserName instead of a textbox then in code behind it does not get declared.
So I declare it by

Dim UserID as Int32

Does this mean I have already converted UserID and so do not have to use Convert.Toint32 (UserID.text)

but then in my parameters

myCommand.Parameters.Add(New SqlParameter("@.MemberID", SqlDbType.Int, 4))
myCommand.Parameters("@.MemberID").Value = UserID.what goes here? I only get a few choices and was hoping for 'value'

I'm sure this is wrong!
Thanks again.
JB
This is a totaly wrong assumption you make there..

Look at:

http://www.asp.net/Tutorials/quickstart.aspx

And find yourself a few samples to play with. It will help you to get the ideas one-by-one..

For the code above:


Dim UserID as Int32
//set the user id to 1
UserID = 1

myCommand.Parameters.Add(New SqlParameter("@.MemberID", SqlDbType.Int, 4))

//set my param to the value of the userid var.
myCommand.Parameters("@.MemberID").Value = UserID


Actually, you're pretty close already.

First off let's change the tag a bit.

<input name="UserID" type="hidden" value="<% =Session.Item("UserID") %>" /
Now, when you pull up the page, if you do a View | Source, you should see that tag on your page, with your UserID set as the value. If it doesn't have a value, then there is something wrong with your session variable that you need to hunt down.

Next, in you're code, you'll have this:

Dim UserID as Int32
'Now we have the variable, but we still have to assign it a value.

UserID = Convert.ToInt32(Request.Form("UserID"))
'Now that we have the UserID in the variable, pass it to the command object.

myCommand.Parameters.Add(New SqlParameter("@.MemberID", SqlDbType.Int, 4))
myCommand.Parameters("@.MemberID").Value = UserID
Thanks,

I have looked through all the quickstarts but canot find this.
All my other parameters pass properly except this one
The value must equal the hidden input session variable from the form but it just passes a "0"

Thanks for the help so far.
JB
Xanderno

That's fixed it!!

Thanks to you and the others for taking time to help me.
Cheers,
JB

Saturday, March 24, 2012

Passing a "where" claus to populate a datagrid on another form.

I have a form where a user can enter mulitple search criteria. Depending upon what they choose I begin stringing the information into a string field that I pass to another form.

It is my intention to open this form that contains a datagrid which returns the records that match their search criteria.

I have had success sending the information, but I am completely lost as to how I use this information.

I dragged the dbconnection, the dataadapter and created the dataset onto the form, but I am not sure if this is how I should have done it. Perhaps all of this should be done in code and create the select string in code for the dataadapter? Does anyone have code that they could share the accomplishes this?

Currently the form brings up all records, (before I started tinkering), but I do not know how to set the 'where' claus.

Thanks for your helpHere is some of the code I am working with:

Dim conn As New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=c:\Access_ResourceDB\Access_ResourceDb_Backend\ResourceDb_be.mdb")

Dim ds As New DataSet("MyDataSet")

Dim objCmd As New OleDbDataAdapter("Select RecId,Name,Age,Town,HowmPhone,Email FROM tblContacts " & "Where " & pasRecCrit & ";", conn)

conn.Open()
objCmd.Fill(ds, "MyDataSet")
Me.DataGrid1.DataSource = ds.Tables("MyDataSet")
Me.DataGrid1.DataBind()

This is just one of the ways I have tried. Right now I get an error stating that
"No value given for one or more required parameters", on the objCmd.fill line.
Thanks
What do have in the pasRecCrit variable? This looks like it should work. Maybe your Where clause isn't formatted correctly.

Wednesday, March 21, 2012

passing a non-databound column to javascript

I have a gridView with a template field that looks like this
<asp:TemplateField HeaderText="">
<ItemTemplate>
<a href="http://links.10026.com/?link=javascript:OpenHelp('<%# Eval("Status") %>')">
<img alt="Click for help." src="http://pics.10026.com/?src=help\help.gif" border="0px"
width="12px"/>
</a>
</ItemTemplate>
</asp:TemplateField>
This works great in a test grid where status is actually bound to the
database. However in the real case Status is not bound but is a column
populated based on complex logic from many fields. I know the whole Eval thi
s
is for databound stuff, but how do I pass it when it is not databound? The
"Status" column is another template field with header text = "Status".You can perform any operations using the <%# %> using page or static utility
classes/methods that you could using, say, <%= %> or in your code behind.
Perhaps the best solution would be to do something like this:
public static class MyDataManager
{
public static string GetComplexStatus(object val1, object val2, object
val3)
{
// Do any normal logic you would do to determine what the status is
// then return it to the caller.
return string.Format("{0} : {1} : {2}", val1, val2, val3);
}
}
Then on your page, you could call this like:
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<a href="http://links.10026.com/?link=java script:OpenHelp('<%#
MyDataManager.GetComplexStatus(Request.Url, Eval("MyField1"),
this.protectedPageVariable1) %>')">
<img alt="Click for help." src="http://pics.10026.com/?src=help\help.gif" border="0px"
width="12px"/>
</a>
</ItemTemplate>
</asp:TemplateField>
This example shows pulling values that are not necessarily databound, but
perhaps are page variables (protected +), properties, other methods, static
methods or properties, and maybe even another data bound field.
Hope this helps.
Chad Scharf
_______________________________
http://www.chadscharf.com
"rlm" wrote:

> I have a gridView with a template field that looks like this
> <asp:TemplateField HeaderText="">
> <ItemTemplate>
> <a href="http://links.10026.com/?link=java script:OpenHelp('<%# Eval("Status") %>')">
> <img alt="Click for help." src="http://pics.10026.com/?src=help\help.gif" border="0px"
> width="12px"/>
> </a>
> </ItemTemplate>
> </asp:TemplateField>
> This works great in a test grid where status is actually bound to the
> database. However in the real case Status is not bound but is a column
> populated based on complex logic from many fields. I know the whole Eval t
his
> is for databound stuff, but how do I pass it when it is not databound? The
> "Status" column is another template field with header text = "Status".
>
Chad, thanks. Is there a way to simply reference the value/string that is
already in the table cell on the rendered page, and pass that to javascript?
Sure...
In your header, or somewhere before the databound control (repeater,
datagrid, etc), place something like this:
<script type="text/javascript">
<!--
var myVal;
//-->
</script>
Then inside of your <ItemTemplate />:
...
<ItemTemplate>
<script type="text/javascript">
<!--
myVal = '<%# Eval("ColumnName") %>';
//-->
</script>
<%-- Or you could use it in this fashion --%>
<asp:Button runat="server" ID="myButton" Text="Click Me"
OnClientClick='<%# string.Format("alert('{0}');return false;",
Eval("ColumnName")) %>' />
</ItemTemplate>
Chad Scharf
_______________________________
http://www.chadscharf.com
"rlm" wrote:

> Chad, thanks. Is there a way to simply reference the value/string that is
> already in the table cell on the rendered page, and pass that to javascrip
t?
>
Chad,
I will try these suggestions out later today, but I don't see how this last
one is much different than my first post "javascript:OpenHelp('<%#
Eval("Status") %>')" which does not work. The Eval on the non bound Template
Field did not work. I guess I am still missing something in my understanding
.
This line
myVal = '<%# Eval("Status") %>';
produces this error
DataBinding: 'System.Data.DataRowView' does not contain a property with the
name 'Status'.
because the field is not databound.

> <ItemTemplate>
> <script type="text/javascript">
> <!--
> myVal = '<%# Eval("ColumnName") %>';
> //-->
> </script>
>
OK, I misunderstood the actual issue you were having; my apologies. I've run
into this issue a few times in the past when binding a DataTable or DataSet
to a databound control.
Are you using a SqlDataSource control, binding via code behind, etc? Please
ensure that the column "Status" is in your select list, if it is not, then
your code below would fail with this error. If you are using Typed datasets,
please ensure that the property settings for the Status column is
pass-through to the associated DataView, especially if it is a calculated
column or relies on an expression for its value.
Set a break-point in the Control_ItemDataBound event and explore your item's
datasource to ensure this column is present.
If the column/value is indeed there, you may as I have done in the past use
a typed expression to retrieve it and see how that works for you, e.g.:
<%# ((System.Data.DataRowView)Container.DataItem).Row["Status"] %>
Thanks,
Chad Scharf
_______________________________
http://www.chadscharf.com
"rlm" wrote:

> This line
> myVal = '<%# Eval("Status") %>';
> produces this error
> DataBinding: 'System.Data.DataRowView' does not contain a property with th
e
> name 'Status'.
> because the field is not databound.
>
>
To expand on this a little further going back, I do want to point out that
your ItemTemplate is still a DataBound field, even if it is keying off of th
e
"Status" column which is not directly from your Database itself.
The Eval(); method is intended to pull a property or reference point from a
data item, which inheritly is the assigned object from the enumerator bound
to your control. This object, whether it is a DataRowView or perhaps a custo
m
class, must contain the property or accessor for the Eval("") expression you
provided, if it does not you will reiceve that databinding error.
It sounds as if your "Status" column is a calculated field within a typed
DataSet, or is added via another method in your code. If this is true, use
the debugger to trace your databinding events to ensure this column is being
generated properly, that the AcceptChanges(); method is called on your
DataSet - OR - for pending changes or for safety sake, use the .Select()
method on your DataTable rather than allowing the DataBinding evaluator call
the DataRowView:
...
DataRow[] source = myTable.Select();
if (source.Length > 0)
MyDataBoundControl.DataSource = myTable.Select();
else
MyDataBoundControl.DataSource = null; // zero length collections not
allowed
MyDataBoundControl.DataBind();
...
Let me know what you find.
Chad Scharf
_______________________________
http://www.chadscharf.com
"Chad Scharf" wrote:
> OK, I misunderstood the actual issue you were having; my apologies. I've r
un
> into this issue a few times in the past when binding a DataTable or DataSe
t
> to a databound control.
> Are you using a SqlDataSource control, binding via code behind, etc? Pleas
e
> ensure that the column "Status" is in your select list, if it is not, then
> your code below would fail with this error. If you are using Typed dataset
s,
> please ensure that the property settings for the Status column is
> pass-through to the associated DataView, especially if it is a calculated
> column or relies on an expression for its value.
> Set a break-point in the Control_ItemDataBound event and explore your item
's
> datasource to ensure this column is present.
> If the column/value is indeed there, you may as I have done in the past us
e
> a typed expression to retrieve it and see how that works for you, e.g.:
> <%# ((System.Data.DataRowView)Container.DataItem).Row["Status"] %>
> Thanks,
> --
> Chad Scharf
> _______________________________
> http://www.chadscharf.com
>
> "rlm" wrote:
>
I have not been able to force the "Status" field into the default view. Ther
e
is no such fielld in the table, and debugging has not helped me.
Anyone can reproduce this in less than three minutes(if they already have a
database to connect to) with the following steps
1. create new web application
2. drop on a grid view
3. Choose datasource (sql)
4 connect to any table and select some fields
5. On gridView tasks choose Edit Columns
6. Add a template field
7. Change its header text to status
8. use RowDataBound event to set the value in that field with something like
this
e.Row.Cells[2].Text = "happy";
9. Pass that fields value to a javascript function like this
<ItemTemplate>
<a href="http://links.10026.com/?link=java script:OpenHelp('<%# Eval("Status") %>')">
Text
</a>
</ItemTemplate>
Oooh, that's what you meant by "not databound." That makes sense now and so
does the exception and what you're trying to accomplish.
You can do this many ways, however the easiest is to do the following:
e.Row.Cells[2].Text = string.Format("<a href=\"\"
onclick=\"java script:OpenHelp('{0}');return false;\">{0}</a>", status);
When you set the Text of a cell in a DataBound row inside of a GridView, you
would be replacing the content of that cell (inlcuding whatever the
ItemTemplate specified) anyways.
Other ways you can accomplish this are with protected page level variables
to store the databound value in, then in your ItemTemplate use the <%# myVar
%> syntax instead of Eval("").
Thanks,
Chad Scharf
_______________________________
http://www.chadscharf.com
"rlm" wrote:

> I have not been able to force the "Status" field into the default view. Th
ere
> is no such fielld in the table, and debugging has not helped me.
> Anyone can reproduce this in less than three minutes(if they already have
a
> database to connect to) with the following steps
> 1. create new web application
> 2. drop on a grid view
> 3. Choose datasource (sql)
> 4 connect to any table and select some fields
> 5. On gridView tasks choose Edit Columns
> 6. Add a template field
> 7. Change its header text to status
> 8. use RowDataBound event to set the value in that field with something li
ke
> this
> e.Row.Cells[2].Text = "happy";
> 9. Pass that fields value to a javascript function like this
> <ItemTemplate>
> <a href="http://links.10026.com/?link=java script:OpenHelp('<%# Eval("Status") %>')">
> Text
> </a>
> </ItemTemplate>
>

passing a value into a global variable....

i have a global variable in which i want to pass a value taken from a field in a database.

Dim Number1 as Integer
Dim RAnswer as Integer

Sub Start_Click

'other coding goes here..............

Number1 = objDataReader("QNo")
RAnswer = objDataReader("QAns")

End sub

i need the value taken from QNo, and passed into the global variable Number1 so that i can use the value inside Number1 in another subroutine. can anyone tell me how to do this...
ThanxIs there anything wrong you are encountering? You might try casting the result of the reader to an Integer.

Number1 = CInt( objDataReader("QNo") )

Friday, March 16, 2012

passing a value to a hidden form field

Hi

Newbie Question:

I have a dataset called "mxdata" that has a field called "mxorder" with an integer value.

I want to increment that value by 1 and pass the new value to a hidden form field.

ie:

variablex = mxdata.mxorder + 1

<input name="ordervalue" type="hidden" id="ordervalue" value="<%# variablex %>"/
Obviously this is incorrect. Can someone show me how I would do this?why not just add it to the viewstate?, the ultimate hidden field of all time :-)

ViewState("orderValue") = mxdata.mxorder + 1

then after a postback you can retrive it like this

somevar = cint(ViewState("orderValue"))