Showing posts with label access. Show all posts
Showing posts with label access. Show all posts

Thursday, March 29, 2012

Passing Value Query

Hi,

I have an e-commerce website written in asp 1.1, vb.net and utilising an access database. Within the database I have a ProductID value to identify each product. Within the following sub procedure I want to be able to reference this value as I want to be able to check if there are enough items in stock. The code below uses the cartitemID and quantity as variables. However to reference individual items in the database I surely will need to pass the ProductID value. How should I approach this ?

[CODE]

Sub dgCart_Update(sender As Object, e As DataGridCommandEventArgs)

Dim intCartitemID As Integer
Dim txtQuantity As TextBox
Dim intQuantity As Integer

'Passes ProductID as sender

'Dim intProductID As Integer ??

intCartitemID = dgCart.DataKeys(e.Item.ItemIndex)
txtQuantity = e.Item.FindControl("txtQuantity")
intQuantity = txtQuantity.Text

'Define intQuantityInStock and reference to CheckQuantity function
Dim intQuantityInStock As Integer = CheckQuantity(intProductID)

'If statement to check enough quantity in stock
If intQuantityInStock < intQuantity
lblError.Text = "This item is currently low in stock. Please select an alternative</b>"
lblError.Visible = True
Else
Dim strSQL As String = "UPDATE [tblCartItems] SET [intQuantityOrder]=@dotnet.itags.org.Quantity WHERE "& _
"intCartitemID = @dotnet.itags.org.intCartitemID"

Dim dbCommand As New OleDbCommand(strSQL, dbConnection)

Dim cmd As New OleDbCommand

dbCommand.Parameters.Add("@dotnet.itags.org.Quantity", intQuantity)
dbCommand.Parameters.Add("@dotnet.itags.org.intCartitemID", intCartitemID)

dbConnection.Open()
dbCommand.ExecuteNonQuery()
dbConnection.Close()

dgCart.EditItemIndex = -1
dgCart.DataSource = DisplayCart()
dgCart.DataBind()

End If

End Sub
[/CODE]

You should be able to set this value in, say the CommandArgument of the button that is being clicked

ex:

<asp:Button
ID="btnAddToCart" runat="server"
CommandArgument='<%# Eval( "ProductID" ) %>'
CommandName="Product"
Text="Add To Cart" />

Then in your code behind, assign intProductID = (int) e.CommandArgument

Depending on what else you are doing with your grid, you may have to wrap an "if" around some code, checking if e.CommandName == "Product"


Thanks - unfortunately I'm not using a button in this instance. How else could I approach it ?


Fixed it thanks

Passing values between client and server side (Javascript to C#)

I would like to access client side values from the code behind.

Say I open a window like this

 popWindow = window.open("data_list.aspx","dataWindow",'toolbar,width=150,height=100')
 How can I get the window name "dataWindow" from that current window or the parent window?
 Any other examples accessing variables between server side (C#) and client side (JavaScript) would be greatly appreciated.
 Regards -WH 

Page.Request.ServerVariables["SCRIPT_NAME"] will get the name of the current page. You can also pass values in a querystring, which will make them accessible to server-side code.
thanks, Page.Request.ServerVariables["SCRIPT_NAME"] worked out for me.

Saturday, March 24, 2012

passing variables

hi,

When my user logs on they suppy a username thats checked off a db to allow access. This username is the unique identifier for all queries that are run throughout the access. What is the best way to pass this between pages. I will have a number of clients accessing at the same time. The variable is a six character alphanumeric.

any ideas will be accepted gratefully....oh security is a key issue as i dont want users getting access to eachothers identifier.

tia

pecSee if below two links could helps for your question

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskpassingvaluesbetweenwebformspages.asp

and

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconpassingservercontrolvaluesbetweenpages.asp

If not you could capture the value in sessions and you can use it in all the pages!

Hope it helps!
hi

i followed the first links eg...but when i use sourcepage.property1 it isnt within the object

any ideas

pec
In this given example in first page he given a property1 as property, so if you have that then only you will able to access it!

Hope it helps!
hi,

I had set the property code with in my <script> in html. When i moved it to the vb it worked but when i ran it the called page gave this error...even though i have placed the Public sourcepage As WebForm1 in the right place?

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'sourcepage' is not declared.

Source Error:

Line 15:
Line 16: If Not IsPostBack Then
Line 17: sourcepage = CType(Context.Handler, logon)
Line 18: dim strUserName as string = sourcepage.Username
Line 19: mydatagrid.Visible = False

tia pec
Declare sourcepage, then use it!

Ex: Dim sourcepage As PreviousPage

In this case PreviousPage is the first page reference name!

That could solve your problem!

Passing Variables between applications

I have two applications and both of them are compiled separatly.

Now I need to access the variables of one application from other application.

In other words I need to transfer the value of one variable from one application to another.

How can I do that ??Chapter 6 of ASP.NET Unleashed, "Using Code-Behind", goes into this (if you have the book). It basically discusses the ranges of public functions and variables (vs private, protected..) That is what you will want to reference to.

Basically, if you have a .CS file or, (i think the same is true when you compile)..

You have something like this (this is taken from the book)..

You CS file looks like


using System;

namespace myComponents {

public class AdderProperties {

private int _firstValue;
private int _secondValue;

public int FirstValue {
get {
return _firstValue;
}
set {
_firstValue = value;
}
}

public int SecondValue {
get {
return _secondValue;
}
set {
_secondValue = value;
}
}

int AddValues() {
return _firstValue + _secondValue;
}

}

}

And you ASP.NET page looks like this


<%@. Import Namespace="myComponents" %
<script runat=server>
void Button_Click( object s, EventArgs e )
{
Adder myAdder = new Adder();

myAdder.FirstValue = Int32.Parse(txtVal1.Text);
myAdder.SecondValue = Int32.Parse(txtVal2.Text);
lblOutput.Text = myAdder.AddValues().ToString();
}
</Script
<html>
<head><title>AddValues.aspx</title></head>
<body
<form Runat="Server"
Value 1:
<asp:TextBox
ID="txtVal1"
Runat="Server" /
<p
Value 2:
<asp:TextBox
ID="txtVal2"
Runat="Server" /
<p>
<asp:Button
Text="Add!"
OnClick="Button_Click"
Runat="Server" /
<p>
Output:
<asp:Label
ID="lblOutput"
Runat="Server" /
</form
</body>
</html

Is this what you are looking to do? Separate business(or w/e) logic from presentation? I am pretty sure that one application can pass information to another application using the same method.
You could do a POST (WebRequest/WebResponse objects) to a page in the "receiving" application. You could also put the data in some "shared" space (a database for example).

HTH...

Chris
but I think this example will work if both the applications are part of the same solution. What if both the applications are part of the different solutions.

Thanks,
azamsharp
What is

Adder myadder = new Adder();

should'nt this be :

AdderProperties adder = new AdderProperties()
Haha, yah.. I copied the wrong file :\ your Adder class should look like

using System;

namespace myComponents {
public class Adder {
public int FirstValue;
public int SecondValue;

public int AddValues() {
return FirstValue + SecondValue;
}

}
}

The original one I posted dealt with adding properties, too.
Hello, have u thought of sharing the same database ? then, you can store variables in one database and access it from multiple applications ?

regards

Passing Variables Between Pages

I have a problem passing information between pages.

I have a page (SendingPage.aspx) that uses the DataReader to gather data from an Access Database and populates a label with the created variable.
<asp:Label id="lbl1" runat="server" text="<%# streetNuml %
This works just fine.

I then want to pass the data in 'lbl1" to another page (ReceivingPage.aspx) on a button click using

httpContext.Current.Items.Add( "StreetNumu", lbl1.text)
Server.Transfer("ReceivingPage.aspx")

and populate a text box

textbox1.text = HttpContext.Current.Items( "StreetNum" )

but it does work. Blank textbox.

Any help or a solution would be greatly appreciated. Thanks DylanTry using the Server.Transfer method overload that preserves the form variables.

Server.Transfer("blah.aspx", True)
I don't believe this will work even with the preserveForm parameter set to true.

Server.Transfer only preserves the Forms and QueryString collection which is read-only on the server-side. So it is not possible to add something to the collection so that the destination page will be able to reference it.

In this case it might be better to use a simple Response.Redirect with a querystring in order to pass the value.

hope this helps,
sivilian
Thank You for the replies. I've tried both techniques mentioned.

I think the main question, and I've realized this recently, is how to convert a
dynamic variable <%# ...... %> to a static variable that is not associated with the value provided by the database. I think this is possible, but how? Any thoughts.... Thanks again.

Cheers

Dylan

Friday, March 16, 2012

password field: Syntax error in INSERT INTO statement.

Hello,
I am trying to execute ADO.NET INSERT statement where one of the
fields
is coming from a password HTML control. When I access the text with
password.Value and print with Response.Write so as to check that it
is working correctly it displays just fine. However, whenever I
include the password field in one of the SQL INSERT statement's
fields I get the following error:
Exception Details: System.Data.OleDb.OleDbException: Syntax error in
INSERT INTO statement.
Line 85: cmd.ExecuteNonQuery();
When I delete the password field from the insert statement things work
fine (so the problem is no longer related to NTFS file permissions).
Any ideas on how to solve this problem would be greatly appreciated.
Best Regards,
NeilNeil, it's difficult to pinpoint your problem without seeing some code; but
here are a few ideas to get you started;
If you're using a WebControls textbox (and not an HtmlControls input box),
then the correct accessor would be something like txtPassword.Text
Triple-check your SQL. Try modifying it so that the value you're entering
in the textbox is manually assigned to the SqlParam (or embedded in your sql
string, etc). That will help you debug your SQL, your schema, etc while
removing the textbox from the equation.
Try very simple passwords, e.g. "a". If that succeeds, you might be having
a problem with unescaped apostrophes or something similar.
If you can, display the generated Sql in a Trace.Write or a Response.Write,
and copy/paste it into your Sql tool to test it manually.
Best of luck,
/// M
"Neil Zanella" <nzanella@.gmail.com> wrote in message
news:1ac72686.0501221942.349922c2@.posting.google.com...
> Hello,
> I am trying to execute ADO.NET INSERT statement where one of the
> fields
> is coming from a password HTML control. When I access the text with
> password.Value and print with Response.Write so as to check that it
> is working correctly it displays just fine. However, whenever I
> include the password field in one of the SQL INSERT statement's
> fields I get the following error:
> Exception Details: System.Data.OleDb.OleDbException: Syntax error in
> INSERT INTO statement.
> Line 85: cmd.ExecuteNonQuery();
> When I delete the password field from the insert statement things work
> fine (so the problem is no longer related to NTFS file permissions).
> Any ideas on how to solve this problem would be greatly appreciated.
> Best Regards,
> Neil
Hello,
Thank you for your reply. I have already tried everything
you suggested. I also had a problem with calling
Response.Write to debug my SQL query as
whenever I use it the parameter holders
which begin with @. are not substituted
when I call Response.Write (is there
some special method I can call on
OleDbCommand to print the actual
query with the parameters
substituted in?)
Anyways, here was my problem: as strange as
it may sound, I renamed a field called "password"
in MS Access to "foo" and did the same in the
query contained in the code. I don't know how
come but that fixed it. Is there something
special about calling a table's field
"password" in MS Access which
causes the query error I was
experiencing'
Thanks,
Neil
It might be a reserved word in Access. In Sql Server you can use most
reserved words as column names, but you reference them in your sql using
[brackets].
Since you've identified it as an Access or .NET->Access issue, I'd also try
seaching some of those newsgroups.
<nzanella@.gmail.com> wrote in message
news:1106607939.521494.187670@.f14g2000cwb.googlegroups.com...
> Hello,
> Thank you for your reply. I have already tried everything
> you suggested. I also had a problem with calling
> Response.Write to debug my SQL query as
> whenever I use it the parameter holders
> which begin with @. are not substituted
> when I call Response.Write (is there
> some special method I can call on
> OleDbCommand to print the actual
> query with the parameters
> substituted in?)
> Anyways, here was my problem: as strange as
> it may sound, I renamed a field called "password"
> in MS Access to "foo" and did the same in the
> query contained in the code. I don't know how
> come but that fixed it. Is there something
> special about calling a table's field
> "password" in MS Access which
> causes the query error I was
> experiencing'
> Thanks,
> Neil
>

password field: Syntax error in INSERT INTO statement.

Hello,

I am trying to execute ADO.NET INSERT statement where one of the
fields
is coming from a password HTML control. When I access the text with
password.Value and print with Response.Write so as to check that it
is working correctly it displays just fine. However, whenever I
include the password field in one of the SQL INSERT statement's
fields I get the following error:

Exception Details: System.Data.OleDb.OleDbException: Syntax error in
INSERT INTO statement.

Line 85: cmd.ExecuteNonQuery();

When I delete the password field from the insert statement things work
fine (so the problem is no longer related to NTFS file permissions).

Any ideas on how to solve this problem would be greatly appreciated.

Best Regards,

NeilNeil, it's difficult to pinpoint your problem without seeing some code; but
here are a few ideas to get you started;

If you're using a WebControls textbox (and not an HtmlControls input box),
then the correct accessor would be something like txtPassword.Text

Triple-check your SQL. Try modifying it so that the value you're entering
in the textbox is manually assigned to the SqlParam (or embedded in your sql
string, etc). That will help you debug your SQL, your schema, etc while
removing the textbox from the equation.

Try very simple passwords, e.g. "a". If that succeeds, you might be having
a problem with unescaped apostrophes or something similar.

If you can, display the generated Sql in a Trace.Write or a Response.Write,
and copy/paste it into your Sql tool to test it manually.

Best of luck,

/// M

"Neil Zanella" <nzanella@.gmail.com> wrote in message
news:1ac72686.0501221942.349922c2@.posting.google.c om...
> Hello,
> I am trying to execute ADO.NET INSERT statement where one of the
> fields
> is coming from a password HTML control. When I access the text with
> password.Value and print with Response.Write so as to check that it
> is working correctly it displays just fine. However, whenever I
> include the password field in one of the SQL INSERT statement's
> fields I get the following error:
> Exception Details: System.Data.OleDb.OleDbException: Syntax error in
> INSERT INTO statement.
> Line 85: cmd.ExecuteNonQuery();
> When I delete the password field from the insert statement things work
> fine (so the problem is no longer related to NTFS file permissions).
> Any ideas on how to solve this problem would be greatly appreciated.
> Best Regards,
> Neil
Hello,

Thank you for your reply. I have already tried everything
you suggested. I also had a problem with calling
Response.Write to debug my SQL query as
whenever I use it the parameter holders
which begin with @. are not substituted
when I call Response.Write (is there
some special method I can call on
OleDbCommand to print the actual
query with the parameters
substituted in?)

Anyways, here was my problem: as strange as
it may sound, I renamed a field called "password"
in MS Access to "foo" and did the same in the
query contained in the code. I don't know how
come but that fixed it. Is there something
special about calling a table's field
"password" in MS Access which
causes the query error I was
experiencing??

Thanks,

Neil
It might be a reserved word in Access. In Sql Server you can use most
reserved words as column names, but you reference them in your sql using
[brackets].

Since you've identified it as an Access or .NET->Access issue, I'd also try
seaching some of those newsgroups.

<nzanella@.gmail.com> wrote in message
news:1106607939.521494.187670@.f14g2000cwb.googlegr oups.com...
> Hello,
> Thank you for your reply. I have already tried everything
> you suggested. I also had a problem with calling
> Response.Write to debug my SQL query as
> whenever I use it the parameter holders
> which begin with @. are not substituted
> when I call Response.Write (is there
> some special method I can call on
> OleDbCommand to print the actual
> query with the parameters
> substituted in?)
> Anyways, here was my problem: as strange as
> it may sound, I renamed a field called "password"
> in MS Access to "foo" and did the same in the
> query contained in the code. I don't know how
> come but that fixed it. Is there something
> special about calling a table's field
> "password" in MS Access which
> causes the query error I was
> experiencing??
> Thanks,
> Neil