Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Monday, March 26, 2012

Pass Username and Pwd to database query in WebMartix?

I have an application that uses a login screen to pass UserName and Password to a details page. Then I use a SELECT query to generate a datagrid using UserName and Pwd as WHERE clause.

I have inserted a couple of label.texts to verify the variable make the second page.

How do I get the query to limit the return to only the records matching the UserName & Pwd combination?

Thanks,
ScottYou don't really want to pass the password around your site. And hopefully you're not allowing multiple duplicate usernames as long as the password is different.

If you're using asp.net authentication then it's somewhat safe to assume that the username is valid once they're logged in.

I.E. on your login page you set an authorization cookie.

On your details page you access their username via this cookie and use that as a parameter to your stored procedure/SQL Query.

Pass value from javascript to vb.net to database without postback...Possible?

Hi,
I have a complicated question that I'm hoping someone can help me out
with. I have a webpage that contains a plug-in. This plug-in can
communicate/pass data with the webpage that contains it via javascript.
What I need to be able to do is take that data passed via javascript
and, using vb.net as the code behind language, send it to a database
without posting it because when I post, the plugin is reloaded and
starts at the beginning. Specifcally, the plug-in is a type of
educational program, when the user completes a certain objective in the
program, I need to store that info in the database but not have the
program start back at the beginning.
What happens currently is upon completing the objective in the plugin,
a javascript function is called in the containing webpage. That
javascript function changes the data in a hidden field runat the
server. I artificially create a postback using the
document.forms.submit() function, then in the page_load function in the
codebehind page I check the value of the hidden field and store it to
the database. This works fine. The problem is that when the page
reloads, my plug-in is reloaded and instead of the user being at say
level 6, they are back at the initial level 1. Ideally, I would like to
send the information to the database without having to reload the page
and was wondering if this was possible.
Thanks in advance and I'll be happy to clarify any questions.
AndyYou would need to do something like use XMLHTTP to issue a call to a page to
do the work. However, I think that ties you to IE 5.5 and above. This may
or may not be a problem for you.
"Andy" <acs974@.hotmail.com> wrote in message
news:1129749048.607189.307420@.g44g2000cwa.googlegroups.com...
> Hi,
> I have a complicated question that I'm hoping someone can help me out
> with. I have a webpage that contains a plug-in. This plug-in can
> communicate/pass data with the webpage that contains it via javascript.
> What I need to be able to do is take that data passed via javascript
> and, using vb.net as the code behind language, send it to a database
> without posting it because when I post, the plugin is reloaded and
> starts at the beginning. Specifcally, the plug-in is a type of
> educational program, when the user completes a certain objective in the
> program, I need to store that info in the database but not have the
> program start back at the beginning.
> What happens currently is upon completing the objective in the plugin,
> a javascript function is called in the containing webpage. That
> javascript function changes the data in a hidden field runat the
> server. I artificially create a postback using the
> document.forms.submit() function, then in the page_load function in the
> codebehind page I check the value of the hidden field and store it to
> the database. This works fine. The problem is that when the page
> reloads, my plug-in is reloaded and instead of the user being at say
> level 6, they are back at the initial level 1. Ideally, I would like to
> send the information to the database without having to reload the page
> and was wondering if this was possible.
> Thanks in advance and I'll be happy to clarify any questions.
> Andy
>
the easiest approach is a hidden iframe/frame.
1) the src of the hidden frame should be an aspx page with hidden fields.
the clientscript would fill in the hidden fields in the frame, and do a
submit of the frame.
2) create an addtional form (nonserver) on the page with the target the
hidden frame, have the client script fill in the hidden fields in the form
and do a submit.
-- bruce (sqlwork.com)
"Andy" <acs974@.hotmail.com> wrote in message
news:1129749048.607189.307420@.g44g2000cwa.googlegroups.com...
> Hi,
> I have a complicated question that I'm hoping someone can help me out
> with. I have a webpage that contains a plug-in. This plug-in can
> communicate/pass data with the webpage that contains it via javascript.
> What I need to be able to do is take that data passed via javascript
> and, using vb.net as the code behind language, send it to a database
> without posting it because when I post, the plugin is reloaded and
> starts at the beginning. Specifcally, the plug-in is a type of
> educational program, when the user completes a certain objective in the
> program, I need to store that info in the database but not have the
> program start back at the beginning.
> What happens currently is upon completing the objective in the plugin,
> a javascript function is called in the containing webpage. That
> javascript function changes the data in a hidden field runat the
> server. I artificially create a postback using the
> document.forms.submit() function, then in the page_load function in the
> codebehind page I check the value of the hidden field and store it to
> the database. This works fine. The problem is that when the page
> reloads, my plug-in is reloaded and instead of the user being at say
> level 6, they are back at the initial level 1. Ideally, I would like to
> send the information to the database without having to reload the page
> and was wondering if this was possible.
> Thanks in advance and I'll be happy to clarify any questions.
> Andy
>
Once you're upgraded to ASP.NET 2.0 you can use the new client side
callback feature to do this kind of thing.
Here's more info:
http://www.aspnetpro.com/features/2...p200511so_f.asp
http://www.developer.com/net/asp/article.php/3506896
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Andy" <acs974@.hotmail.com> wrote in message
news:1129749048.607189.307420@.g44g2000cwa.googlegroups.com...
> Hi,
> I have a complicated question that I'm hoping someone can help me out
> with. I have a webpage that contains a plug-in. This plug-in can
> communicate/pass data with the webpage that contains it via javascript.
> What I need to be able to do is take that data passed via javascript
> and, using vb.net as the code behind language, send it to a database
> without posting it because when I post, the plugin is reloaded and
> starts at the beginning. Specifcally, the plug-in is a type of
> educational program, when the user completes a certain objective in the
> program, I need to store that info in the database but not have the
> program start back at the beginning.
> What happens currently is upon completing the objective in the plugin,
> a javascript function is called in the containing webpage. That
> javascript function changes the data in a hidden field runat the
> server. I artificially create a postback using the
> document.forms.submit() function, then in the page_load function in the
> codebehind page I check the value of the hidden field and store it to
> the database. This works fine. The problem is that when the page
> reloads, my plug-in is reloaded and instead of the user being at say
> level 6, they are back at the initial level 1. Ideally, I would like to
> send the information to the database without having to reload the page
> and was wondering if this was possible.
> Thanks in advance and I'll be happy to clarify any questions.
> Andy
>
if you don't need anything back, it's trivial:
var sender = new Image();
sender.src = "whatever.aspx?stufff=1&junkID=27";
Done, and done.
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/
Thanks everyone for their help. It seems that ajax is probably going to
be the way I go. I tried to avoid it since I'm pretty new to this web
programming and didn't understand if it was for me, but it seems that's
what I need long term. One quick question, I've been using asp.net 2.0
but because it is in its beta form, I have avoided exploiting much of
its newer features. How worried do I have to be about creating a
website in 2.0 beta then having it not work on me when the final
release comes out?

Pass value from javascript to vb.net to database without postback...Possible?

Hi,

I have a complicated question that I'm hoping someone can help me out
with. I have a webpage that contains a plug-in. This plug-in can
communicate/pass data with the webpage that contains it via javascript.
What I need to be able to do is take that data passed via javascript
and, using vb.net as the code behind language, send it to a database
without posting it because when I post, the plugin is reloaded and
starts at the beginning. Specifcally, the plug-in is a type of
educational program, when the user completes a certain objective in the
program, I need to store that info in the database but not have the
program start back at the beginning.

What happens currently is upon completing the objective in the plugin,
a javascript function is called in the containing webpage. That
javascript function changes the data in a hidden field runat the
server. I artificially create a postback using the
document.forms.submit() function, then in the page_load function in the
codebehind page I check the value of the hidden field and store it to
the database. This works fine. The problem is that when the page
reloads, my plug-in is reloaded and instead of the user being at say
level 6, they are back at the initial level 1. Ideally, I would like to
send the information to the database without having to reload the page
and was wondering if this was possible.

Thanks in advance and I'll be happy to clarify any questions.

AndyYou would need to do something like use XMLHTTP to issue a call to a page to
do the work. However, I think that ties you to IE 5.5 and above. This may
or may not be a problem for you.

"Andy" <acs974@.hotmail.com> wrote in message
news:1129749048.607189.307420@.g44g2000cwa.googlegr oups.com...
> Hi,
> I have a complicated question that I'm hoping someone can help me out
> with. I have a webpage that contains a plug-in. This plug-in can
> communicate/pass data with the webpage that contains it via javascript.
> What I need to be able to do is take that data passed via javascript
> and, using vb.net as the code behind language, send it to a database
> without posting it because when I post, the plugin is reloaded and
> starts at the beginning. Specifcally, the plug-in is a type of
> educational program, when the user completes a certain objective in the
> program, I need to store that info in the database but not have the
> program start back at the beginning.
> What happens currently is upon completing the objective in the plugin,
> a javascript function is called in the containing webpage. That
> javascript function changes the data in a hidden field runat the
> server. I artificially create a postback using the
> document.forms.submit() function, then in the page_load function in the
> codebehind page I check the value of the hidden field and store it to
> the database. This works fine. The problem is that when the page
> reloads, my plug-in is reloaded and instead of the user being at say
> level 6, they are back at the initial level 1. Ideally, I would like to
> send the information to the database without having to reload the page
> and was wondering if this was possible.
> Thanks in advance and I'll be happy to clarify any questions.
> Andy
Look at AJAX.net
It may take care of your needs in this case.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"Andy" wrote:

> Hi,
> I have a complicated question that I'm hoping someone can help me out
> with. I have a webpage that contains a plug-in. This plug-in can
> communicate/pass data with the webpage that contains it via javascript.
> What I need to be able to do is take that data passed via javascript
> and, using vb.net as the code behind language, send it to a database
> without posting it because when I post, the plugin is reloaded and
> starts at the beginning. Specifcally, the plug-in is a type of
> educational program, when the user completes a certain objective in the
> program, I need to store that info in the database but not have the
> program start back at the beginning.
> What happens currently is upon completing the objective in the plugin,
> a javascript function is called in the containing webpage. That
> javascript function changes the data in a hidden field runat the
> server. I artificially create a postback using the
> document.forms.submit() function, then in the page_load function in the
> codebehind page I check the value of the hidden field and store it to
> the database. This works fine. The problem is that when the page
> reloads, my plug-in is reloaded and instead of the user being at say
> level 6, they are back at the initial level 1. Ideally, I would like to
> send the information to the database without having to reload the page
> and was wondering if this was possible.
> Thanks in advance and I'll be happy to clarify any questions.
> Andy
>
the easiest approach is a hidden iframe/frame.

1) the src of the hidden frame should be an aspx page with hidden fields.
the clientscript would fill in the hidden fields in the frame, and do a
submit of the frame.

2) create an addtional form (nonserver) on the page with the target the
hidden frame, have the client script fill in the hidden fields in the form
and do a submit.

-- bruce (sqlwork.com)

"Andy" <acs974@.hotmail.com> wrote in message
news:1129749048.607189.307420@.g44g2000cwa.googlegr oups.com...
> Hi,
> I have a complicated question that I'm hoping someone can help me out
> with. I have a webpage that contains a plug-in. This plug-in can
> communicate/pass data with the webpage that contains it via javascript.
> What I need to be able to do is take that data passed via javascript
> and, using vb.net as the code behind language, send it to a database
> without posting it because when I post, the plugin is reloaded and
> starts at the beginning. Specifcally, the plug-in is a type of
> educational program, when the user completes a certain objective in the
> program, I need to store that info in the database but not have the
> program start back at the beginning.
> What happens currently is upon completing the objective in the plugin,
> a javascript function is called in the containing webpage. That
> javascript function changes the data in a hidden field runat the
> server. I artificially create a postback using the
> document.forms.submit() function, then in the page_load function in the
> codebehind page I check the value of the hidden field and store it to
> the database. This works fine. The problem is that when the page
> reloads, my plug-in is reloaded and instead of the user being at say
> level 6, they are back at the initial level 1. Ideally, I would like to
> send the information to the database without having to reload the page
> and was wondering if this was possible.
> Thanks in advance and I'll be happy to clarify any questions.
> Andy
Once you're upgraded to ASP.NET 2.0 you can use the cool new client side
callback feature to do this kind of thing.

Here's more info:
http://www.aspnetpro.com/features/2...p200511so_f.asp
http://www.developer.com/net/asp/article.php/3506896

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Andy" <acs974@.hotmail.com> wrote in message
news:1129749048.607189.307420@.g44g2000cwa.googlegr oups.com...
> Hi,
> I have a complicated question that I'm hoping someone can help me out
> with. I have a webpage that contains a plug-in. This plug-in can
> communicate/pass data with the webpage that contains it via javascript.
> What I need to be able to do is take that data passed via javascript
> and, using vb.net as the code behind language, send it to a database
> without posting it because when I post, the plugin is reloaded and
> starts at the beginning. Specifcally, the plug-in is a type of
> educational program, when the user completes a certain objective in the
> program, I need to store that info in the database but not have the
> program start back at the beginning.
> What happens currently is upon completing the objective in the plugin,
> a javascript function is called in the containing webpage. That
> javascript function changes the data in a hidden field runat the
> server. I artificially create a postback using the
> document.forms.submit() function, then in the page_load function in the
> codebehind page I check the value of the hidden field and store it to
> the database. This works fine. The problem is that when the page
> reloads, my plug-in is reloaded and instead of the user being at say
> level 6, they are back at the initial level 1. Ideally, I would like to
> send the information to the database without having to reload the page
> and was wondering if this was possible.
> Thanks in advance and I'll be happy to clarify any questions.
> Andy
if you don't need anything back, it's trivial:

var sender = new Image();
sender.src = "whatever.aspx?stufff=1&junkID=27";

Done, and done.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

--
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/
Thanks everyone for their help. It seems that ajax is probably going to
be the way I go. I tried to avoid it since I'm pretty new to this web
programming and didn't understand if it was for me, but it seems that's
what I need long term. One quick question, I've been using asp.net 2.0
but because it is in its beta form, I have avoided exploiting much of
its newer features. How worried do I have to be about creating a
website in 2.0 beta then having it not work on me when the final
release comes out?
Be very worried! Well, not to scare you or anything but seriously, any new
product in beta is not going to be 100% reliable. That's why they call it
alpha, beta.
That being said, you can do a search on google for a list of issues in beta,
that way you can be aware of what's going to work on final release.

"Andy" wrote:

> Thanks everyone for their help. It seems that ajax is probably going to
> be the way I go. I tried to avoid it since I'm pretty new to this web
> programming and didn't understand if it was for me, but it seems that's
> what I need long term. One quick question, I've been using asp.net 2.0
> but because it is in its beta form, I have avoided exploiting much of
> its newer features. How worried do I have to be about creating a
> website in 2.0 beta then having it not work on me when the final
> release comes out?
>

Pass values

I have the following Stored procedure. There is column named
"tcktreceived" in my database and I want to pass all the rows one by
one to the parameter @dotnet.itags.org.starttime. I don't know how to do it.

CREATE PROCEDURE [twcsan].[usp_DateDiff]
-- Add the parameters for the stored procedure here
@dotnet.itags.org.starttime DateTime

AS
BEGIN
DECLARE @dotnet.itags.org.Diff Varchar(15)
DECLARE @dotnet.itags.org.Day INT
DECLARE @dotnet.itags.org.Hour INT
DECLARE @dotnet.itags.org.Minute INT
DECLARE @dotnet.itags.org.Start_Date DateTime
DECLARE @dotnet.itags.org.End_Date DateTime
DECLARE @dotnet.itags.org.itemReceived DateTime
DECLARE @dotnet.itags.org.ID INT
DECLARE @dotnet.itags.org.message VARCHAR(50)

DECLARE @dotnet.itags.org.table TABLE
(
ItemReceived DateTime,
ID INT,
message text,
Differnce VARCHAR(20)

)
SET NOCOUNT ON;
SET @dotnet.itags.org.Start_Date = @dotnet.itags.org.starttime

SET @dotnet.itags.org.End_Date = GETDATE()
SET @dotnet.itags.org.Day = DATEDIFF( day, @dotnet.itags.org.Start_Date, @dotnet.itags.org.End_Date)
SET @dotnet.itags.org.Hour = DATEDIFF(hour , @dotnet.itags.org.Start_Date, @dotnet.itags.org.End_Date)
SET @dotnet.itags.org.Minute = DATEDIFF(minute , @dotnet.itags.org.Start_Date, @dotnet.itags.org.End_Date)
SET @dotnet.itags.org.Minute = @dotnet.itags.org.Minute-(@dotnet.itags.org.HOUR* 60)
SET @dotnet.itags.org.Hour = @dotnet.itags.org.Hour-(24* @dotnet.itags.org.Day)
SET @dotnet.itags.org.Diff = CONVERT(Varchar, @dotnet.itags.org.Day) +'d ' + CONVERT(Varchar , @dotnet.itags.org.Hour) +
'h ' + CONVERT(Varchar , @dotnet.itags.org.Minute) +'m'

INSERT INTO @dotnet.itags.org.table(ItemReceived, ID, message, Differnce)
select tck.tcktreceived, tck.ticketid,tckmsg.tcktmessage,@dotnet.itags.org.Diff
from tbtickets tck inner join tbticketsmessages tckmsg
on tck.ticketid = tckmsg.ticketid

select * from @dotnet.itags.org.table

ENDI'm not sure what your after, but try looking at using "Cursor" that might
give you what you need.

Pass values

I have the following Stored procedure. There is column named
"tcktreceived" in my database and I want to pass all the rows one by
one to the parameter @dotnet.itags.org.starttime. I don't know how to do it.
CREATE PROCEDURE [twcsan].[usp_DateDiff]
-- Add the parameters for the stored procedure here
@dotnet.itags.org.starttime DateTime
AS
BEGIN
DECLARE @dotnet.itags.org.Diff Varchar(15)
DECLARE @dotnet.itags.org.Day INT
DECLARE @dotnet.itags.org.Hour INT
DECLARE @dotnet.itags.org.Minute INT
DECLARE @dotnet.itags.org.Start_Date DateTime
DECLARE @dotnet.itags.org.End_Date DateTime
DECLARE @dotnet.itags.org.itemReceived DateTime
DECLARE @dotnet.itags.org.ID INT
DECLARE @dotnet.itags.org.message VARCHAR(50)
DECLARE @dotnet.itags.org.table TABLE
(
ItemReceived DateTime,
ID INT,
message text,
Differnce VARCHAR(20)
)
SET NOCOUNT ON;
SET @dotnet.itags.org.Start_Date = @dotnet.itags.org.starttime
SET @dotnet.itags.org.End_Date = GETDATE()
SET @dotnet.itags.org.Day = DATEDIFF( day, @dotnet.itags.org.Start_Date, @dotnet.itags.org.End_Date)
SET @dotnet.itags.org.Hour = DATEDIFF(hour , @dotnet.itags.org.Start_Date, @dotnet.itags.org.End_Date)
SET @dotnet.itags.org.Minute = DATEDIFF(minute , @dotnet.itags.org.Start_Date, @dotnet.itags.org.End_Date)
SET @dotnet.itags.org.Minute = @dotnet.itags.org.Minute-(@dotnet.itags.org.HOUR* 60)
SET @dotnet.itags.org.Hour = @dotnet.itags.org.Hour-(24* @dotnet.itags.org.Day)
SET @dotnet.itags.org.Diff = CONVERT(Varchar, @dotnet.itags.org.Day) +'d ' + CONVERT(Varchar , @dotnet.itags.org.Hour) +
'h ' + CONVERT(Varchar , @dotnet.itags.org.Minute) +'m'
INSERT INTO @dotnet.itags.org.table(ItemReceived, ID, message, Differnce)
select tck.tcktreceived, tck.ticketid,tckmsg.tcktmessage,@dotnet.itags.org.Diff
from tbtickets tck inner join tbticketsmessages tckmsg
on tck.ticketid = tckmsg.ticketid
select * from @dotnet.itags.org.table
ENDI'm not sure what your after, but try looking at using "Cursor" that might
give you what you need.

Saturday, March 24, 2012

Pass variables to database

I have a bunch of code written by another developer. It is all in java script. The user walks through a series of instructions then answers a few questions. The java script tracks the answers, I believe they are using a cookie. At the end of the quiz they receive a certificate of completion that says Congrats (username) you got (##) out of (##) correct, etc. Each (somethinghere) being a variable. The javascript just does a document.write(something.parent);
I want to take what is in the variable and pass it to my SQL Database. I have written code in asp.net that does this but the code uses a text box and you have to put somthing in the text box then click Add and it will pass the variables on to my database. How do I do this with this javascript stuff?

Passing values from javascript to the server-side ASP code can be done by placing the value in a hidden text box, or any control which has a text property.

<SCRIPT Language="JavaScript">
document.Form1.TextBoxName.value = javascript variable
</SCRIPT>
You can retrieve the value on the server-side usingRequest.Form("TextBoxName")when the form is posted back.

hope this helps,
sivilian


Not sure where the final value you need is being displayed. You said a document.write?
Then, you may also want to put that var in a hidden html field, then, in your code behind, find the value...

string myVar = (HtmlInputHidden)(this.FindControl("myHiddenFieldName")).Value;


Hope it helps,
Zath


It seems like you want this to automagically happen, without using a text box and clicking a button.
I am assuming that you are not overly knowledgeable with web based development. So you need to know that, in general, to get info into the database the user has to do an action and post the data back to the server. This would be usually done with a form and a button. as Zath points out you can use a hidden control instead of a textbox. Your javascript that does the document.write could then call document.forms[0].submit() to do the post back to the server. This will refresh the page.
Alternatively, you could look at something fancy like AJAX or Javascript RPC (basically the same things). This is pretty advanced stuff.


Here is an example of my asp page:

<%@.ImportNamespace="System.Data.SqlClient" %>
<%@.ImportNamespace="System.Data" %>
<%@.PageLanguage="VB"Debug="TRUE" %>
<%
Dim conMMTMPAs SqlConnection
Dim strInsertAsString
Dim cmdInsertAs SqlCommand

conMMTMP =New SqlConnection("server=servername;UID=ID;PWD=password;database=DBname")
strInsert ="Insert Into SuperTrain (User,Score) Values ('" & Request.Querystring("User") &"','" & Request.Querystring("Score") &"')"
cmdInsert =New SqlCommand( strInsert, conMMTMP )
conMMTMP.Open()
cmdInsert.ExecuteNonQuery()
conMMTMP.Close()
%>
so usually i would pass something say to the url:http://www.mysite.com/page.aspx?User=Tester&Score=100
bam i have a new record in my database. I also have a page written like this:

<%@.ImportNamespace="System.Data.OleDb" %>
<%@.ImportNamespace="System.Data" %>
<%@.PageLanguage="VB"Debug="true" %>
<ScriptRunat="Server">

Sub Button_Click( sAsObject, eAs EventArgs )
Dim conAuthorsAs OleDbConnection
Dim strInsertAsString
Dim cmdInsertAs OleDbCommand
Dim strFirstNameAsString
conAuthors =New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & Server.Mappath("database.mdb"))
strInsert ="Insert Into tblTest ( au_lname ) Values ( @.FirstName )"
cmdInsert =New OleDbCommand( strInsert, conAuthors )
cmdInsert.Parameters.Add("@.Firstname", txtProductName.Text)
conAuthors.Open()
cmdInsert.ExecuteNonQuery()
conAuthors.Close()
EndSub

</Script>
<html>
<head><title>Insert Parameters</title></head>
<body>
<formRunat="Server">
<h2>Add new Name</h2>
<b>First Name:</b>
<br>
<asp:TextBoxID="txtProductname"Runat="Server"/>
<p>
<asp:ButtonText="Add!"OnClick="Button_Click"Runat="Server"/>
</form>
</body>
</html>
now... I have a page not written by me that is in javascript and I need to pass the variables to an asp page or something so I can get them into my database:
here is part of the page, how do i get this javasrcipt variables into my pages?

<p><b><i><font face="Arial,Helvetica"><font size=+4> <!--RG_TITLE0--><SCRIPT LANGUAGE="JavaScript"><!--

if (parent.pass == 1)

{

document.write(parent.master_title);

}

else

{

document.write(parent.comp_title);

}

//-->

</SCRIPT><!--RG_TITLE1--> </font></font></i></b></center>

<p><br>

<center><table WIDTH="70%" >

<tr>

<td><img height=339

SRC="ribbon.png" height=399 width=159></td>

<td><i><font face="Arial,Helvetica">This certifies that</font></i>

<br>

<p><b><u><font face="Arial,Helvetica"><font size=+2> <!--RG_STUDENT_ID0--><SCRIPT LANGUAGE="JavaScript"><!--

document.write(parent.student_id);

//--></SCRIPT><!--RG_STUDENT_ID1--> </font></font></u></b>

<br>

<p><i><font face="Arial,Helvetica"> <!--RG_ACTION0--><SCRIPT LANGUAGE="JavaScript"><!--

var pass=parent.checkScores();

if (pass == 1){document.write(parent.master_act);

}

else

{document.write(parent.comp_act);

}

//--></SCRIPT><!--RG_ACTION1--> <b> <!--RG_COURSE_NAME_OR_TITLE0-->

passing 30+ parameters

i am developing a asp.net aplication, in that..Form1 has some 30 plus text input boxes.

i use a business logic to insert data into the database,

What will be the optimal way to pass all these parameters to BusinessLogic in a single function call?

Hi

I create a structure and fill up the details and then pass it to the business logic and this works very well for me.

I suggest, you try this approach.


Usually for most of my web apps I create a data access layer (DAL) that is a seperate DLL.

I have all my data modelled in objects and pass only the objects back and forth to the DAL. I sometime mix in the business logic layer (BLL) into the DAL as well depending on how complex the application is. One advantage to this is it is quite easy to slap on any type of a GUI onto you application since the core of the application lives is in the DAL or DAL & BLL.

It will make your life easier maintaining the code in the future as well.


so is it advicable to send them in object arrays

Yes.

You could use generics (templates) to pass them if you like.

List<yourObject> type.


sorry, i dont follow your last post. can you give a sample for say 6 diferrent objects

You can use something like the following:

List<String> myStringList = new List<String>();

myStringList.Add("String1");

myStringList.Add("String2");

Generic type will ensure that you are only inserting the String and not any other object. If you have different objects that you will be inserting you can use an ArrayList or better off List<object>.


List<String> myStringList = new List<String>();

myStringList.Add("Alpha");

myStringList.Add("11 Address");

what is the <String> there?Tongue Tied


String is a type. List<String> means that you are creating a list which will only contain string elements. So, if you have 30 textboxes you can iterate through the textboxes and populate the list. Later if you need to access the values of the textboxes you can put the list into a session variable and then access it on the next page.


List<String> myStringList = new List<String>();

creates a "container" called myStringList which can only host String object. You can put as many String object as you want and pass the List "container" itself as parameter. here is one example.

public ... function (List<string> inputList)
{
...

foreach (string currValue in inputList)
{
// iterate through the List

// Do something

}


return ...;
}


Is the List<String> objectIndexed.

How do i access the individual objects in the list?


It's very simple:

List<string> lstStrings = new List<string>();

lstStrings.Add("Test");

string sTemp = lstStrings[0];

or you could use a foreach

foreach (string sTemp in lstStrings)...


List<string> lstStrings = new List<string>();

i get this error when trying to use that construct

"Error 1 The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)"


add this to the top of your code behind file:

using System.Collections.Generic;


using System.Collections.Generic;using System.Collections.Generic;add this to the top of your code behind file:

using System.Collections.Generic;

Wednesday, March 21, 2012

passing a parameter?

Hi Guys,

I am just starting on ASP.net. I have created this file so far called database.aspx. The file contains this code:


<%@dotnet.itags.org. Page Language="C#" %>
<script runat="server">


void Page_load(object Sender, EventArgs e)
{

// Discover if SKU QueryString contains a value
string SKU = Request.QueryString["SKU"];
if (SKU == "")
Response.Write ("NO SKU");
else
DataGrid1.DataSource = GetProduct();
DataGrid1.DataBind();
}

System.Data.DataSet GetProduct() {

// Connect to Database
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\\test\\database\\test.mdb";
System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);

// SQL
string queryString = "SELECT [Products].Title FROM [Products] WHERE ([Products].SKU = @dotnet.itags.org.SKU)";
System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
dbCommand.CommandText = queryString;
dbCommand.Connection = dbConnection;

//Request SKU # from Querystring then locate prodcut based on SKU #

System.Data.IDataParameter dbParam_SKU = new System.Data.OleDb.OleDbParameter();
dbParam_SKU.ParameterName = "@dotnet.itags.org.SKU";
dbParam_SKU.Value = SKU;
dbParam_SKU.DbType = System.Data.DbType.Int32;
dbCommand.Parameters.Add(dbParam_SKU);


System.Data.IDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter();
dataAdapter.SelectCommand = dbCommand;
System.Data.DataSet dataSet = new System.Data.DataSet();
dataAdapter.Fill(dataSet);

return dataSet;


}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<br />
<br />
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
<!-- Insert content here -->
</form>
</body>
</html>

I am trying to pass the SKU from the page_load into the GetProducts();

Can someone please help me as I have been trying to work this out all afternoon.

Thanks for the help (any other comments about how to speed up or improve the code are much appricitated).Big Smile [:D]

Muller


<%@. Page Language="C#" %>
<script runat="server">


void Page_load(object Sender, EventArgs e)
{

// Discover if SKU QueryString contains a value
string SKU = Request.QueryString["SKU"];
if (SKU == "")
Response.Write ("NO SKU");
else

{
DataGrid1.DataSource = GetProduct(SKU);
DataGrid1.DataBind();

}
}

System.Data.DataSet GetProduct(String SKU) {

// Connect to Database
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\\test\\database\\test.mdb";
System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);

// SQL
string queryString = "SELECT [Products].Title FROM [Products] WHERE ([Products].SKU = @.SKU)";
System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
dbCommand.CommandText = queryString;
dbCommand.Connection = dbConnection;

//Request SKU # from Querystring then locate prodcut based on SKU #

System.Data.IDataParameter dbParam_SKU = new System.Data.OleDb.OleDbParameter();
dbParam_SKU.ParameterName = "@.SKU";
dbParam_SKU.Value = SKU;
dbParam_SKU.DbType = System.Data.DbType.Int32;
dbCommand.Parameters.Add(dbParam_SKU);


System.Data.IDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter();
dataAdapter.SelectCommand = dbCommand;
System.Data.DataSet dataSet = new System.Data.DataSet();
dataAdapter.Fill(dataSet);

return dataSet;


}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<br />
<br />
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
<!-- Insert content here -->
</form>
</body>
</html>


Im not a C# programmer so the syntax might be wrong, but I would pass the SKU in as a parameter to the GetProduct routine...like GetProduct(SKU)

and update the query to something like:
string queryString = "SELECT [Products].Title FROM [Products] WHERE ([Products].SKU = " + SKU + ")";

Of course, you would need to change the function so you could pass in the SKU...OR you could create a module level variable and change that variable in your page load, and use it in your function.

MajorCats


thankswessamzeidan that works great.

MajorCats - Thats exactly the way I use to do it in ASP but in one of my ASP.NET books it says to do it this way to try and reduce the risk of SQL injection attacks. I need to look into this more but if anyone has any thoughts please email/reply to this postBig Smile [:D]

Thanks again

Muller

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 JavaScript function from the database

I'm trying to pass a value to initialize a JavaScript function from inside a
Form.
I haven't had any luck.
Can this be done?
I need to get a value from a database and send it to the JavaScript
function.
Thanks,
Scott Natwicklots of ways:
in the aspx page:
<script>
var myValue = ' <%= getValue() %>';
</script>
or in the code behind
RegisterHiddenField("myValue",getValue();
and have the javascript reference the hidden field. you can register a
script block. if you need it at runtime, the javascript can post to a hidden
iframe/frame.
-- bruce (sqlwork.com)
"Scott Natwick" <nospam@.yahoo.com> wrote in message
news:ncWdnVyYIZbz79LcRVn-hw@.comcast.com...
> I'm trying to pass a value to initialize a JavaScript function from inside
a
> Form.
> I haven't had any luck.
> Can this be done?
> I need to get a value from a database and send it to the JavaScript
> function.
> Thanks,
> Scott Natwick
>
Hi Scott,
Have you had a chance to check bruce's suggestions or have you got any
further ideas on this issue? If you need any further assistance, please
feel free to post here.Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Steven,
Thanks for following up. I believe I have it working now, using the prior
suggestion.
On the C# side, my code looks roughly like this:
String scriptString = "<script language=JavaScript> ";
scriptString += "var ... ";
scriptString += "function FunctionName() {... document.Form1.strValue1.value
...}";
scriptString += "</script> ";
RegisterHiddenField("strValue1", "...");
RegisterHiddenField("strValue2", "...");
RegisterStartupScript("startup", scriptString);
It tests Ok, but I haven't put it into production yet.
Regards,
Scott
"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:qPlTs2UoEHA.2640@.cpmsftngxa06.phx.gbl...
> Hi Scott,
> Have you had a chance to check bruce's suggestions or have you got any
> further ideas on this issue? If you need any further assistance, please
> feel free to post here.Thanks.
>
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
Thanks for your followup Scott!
Anyway, if you have any problems in the future, please feel free to post
here. Thanks.
Have a good day!
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Passing a value to a JavaScript function from the database

Hi Steven,

Thanks for following up. I believe I have it working now, using the prior
suggestion.

On the C# side, my code looks roughly like this:

String scriptString = "<script language=JavaScript> ";
scriptString += "var ... ";
scriptString += "function FunctionName() {... document.Form1.strValue1.value
...}";
scriptString += "</script> ";

RegisterHiddenField("strValue1", "...");
RegisterHiddenField("strValue2", "...");

RegisterStartupScript("startup", scriptString);

It tests Ok, but I haven't put it into production yet.

Regards,
Scott

"Steven Cheng[MSFT]" <v-schang@dotnet.itags.org.online.microsoft.com> wrote in message
news:qPlTs2UoEHA.2640@dotnet.itags.org.cpmsftngxa06.phx.gbl...
> Hi Scott,
> Have you had a chance to check bruce's suggestions or have you got any
> further ideas on this issue? If you need any further assistance, please
> feel free to post here.Thanks.
>
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)Thanks for your followup Scott!

Anyway, if you have any problems in the future, please feel free to post
here. Thanks.
Have a good day!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Passing an array from a function

I have a function that autenticates a user. Generally I just pass back true if the user is in the database, but now I want to pass back the userID and if the user is in the database. My guess is to do this with and array, but I keep having troubles passing it back. Code below.

Error I get is

Compiler Error Message:CS0029: Cannot implicitly convert type 'bool' to 'string[]'

Source Error:

Line 10: String strAuthenticate;Line 11:Line 12: userInfo = Authenticate(username.Text, password.Text);Line 13: strAuthenticate = userInfo[0];Line 14: if(strAuthenticate == "0"){

<code>

void login(Object s, EventArgs e){
String[] userInfo = new String[2];
String strAuthenticate;

userInfo = Authenticate(username.Text, password.Text);
strAuthenticate = userInfo[0];
if(strAuthenticate == "0"){
//creating a cookie to store user info
FormsAuthenticationTicket objTicket;
HttpCookie objCookie;
objTicket = new FormsAuthenticationTicket(1, username.Text, DateTime.Now, DateTime.Now.AddMinutes(240), false,"");
objCookie = new HttpCookie(".ASPXAUTH");
objCookie.Value = FormsAuthentication.Encrypt(objTicket);
Response.Cookies.Add(objCookie);

Response.Redirect("logedIn.aspx");
//FormsAuthentication.RedirectFromLoginPage(username.Text, false);
}
else{
lblLogin.Text = "INCORRECT USER NAME AND/OR PASSWORD";
}
}

bool Authenticate(string strUsername, string strPassword){
OleDbConnection objConn = new OleDbConnection(ConfigurationSettings.AppSettings["backupDataB"]);
OleDbCommand objCmd;
OleDbDataReader objDR;
bool userFound;
String userID;
String[] userInfo = new String[2];

objCmd = new OleDbCommand("SELECT * FROM users WHEREemail=@dotnet.itags.org.strUsername ANDPassword=@dotnet.itags.org.strPassword", objConn);
//get userID from this query and store it in a ticket
objCmd.Parameters.Add("@dotnet.itags.org.strUsername", strUsername);
objCmd.Parameters.Add("@dotnet.itags.org.strPassword", strPassword);

objConn.Open();
objDR = objCmd.ExecuteReader();
userFound = objDR.Read();
userID = objDR["userID"];
objDR.Close();
objConn.Close();

userInfo[0] = userFound;
userInfo[1] = userID;

return (String)userInfo;
}

</code>

You'll need to also change the definition of your function to return a string array:

bool Authenticate(string strUsername, string strPassword){

Marcie


I have changed what I think I need to change, but now I get this error and I'm not really sure why.

CS0165: Use of unassigned local variable 'userID'

void login(Object s, EventArgs e){
String[] userInfo = new String[2];
String strAuthenticate;

userInfo = Authenticate(username.Text, password.Text);
strAuthenticate = userInfo[0];
if(strAuthenticate == "0"){
//creating a cookie to store user info
FormsAuthenticationTicket objTicket;
HttpCookie objCookie;
objTicket = new FormsAuthenticationTicket(1, username.Text, DateTime.Now, DateTime.Now.AddMinutes(240), false, userInfo[1]);
objCookie = new HttpCookie(".ASPXAUTH");
objCookie.Value = FormsAuthentication.Encrypt(objTicket);
Response.Cookies.Add(objCookie);

Response.Redirect("logedIn.aspx");
}
else{
lblLogin.Text = "INCORRECT USER NAME AND/OR PASSWORD";
}
}

String[] Authenticate(string strUsername, string strPassword){
OleDbConnection objConn = new OleDbConnection(ConfigurationSettings.AppSettings["backupDataB"]);
OleDbCommand objCmd;
OleDbDataReader objDR;

String userFound = "no";
String userID;
String[] userInfo = new String[2];

objCmd = new OleDbCommand("SELECT * FROM users WHEREemail=@.strUsername ANDPassword=@.strPassword", objConn);
//get userID from this query and store it in a ticket
objCmd.Parameters.Add("@.strUsername", strUsername);
objCmd.Parameters.Add("@.strPassword", strPassword);

objConn.Open();
objDR = objCmd.ExecuteReader();
//"Read" reads each line that is returned from the datareader it starts one above the first record
//if the data is there it will return true if not it will return false. Here it is only examining to see
//if the datareader can read one line. If it can the record does exsit if it can't it means the reader
//returned nothing.
while(objDR.Read()){
userFound = "yes";
userID = objDR.GetString(0);
}
objDR.Close();
objConn.Close();

userInfo[0] = userFound;
userInfo[1] = userID;

return userInfo;
}


Your method signature specifies bool
bool Authenticate(string strUsername, string strPassword){

your return specifies a string
return (String)userInfo;

and userinfo is actually a string array

You need to make all these the same Type


That could happen if your query doesn't return any results (user is not found). You're only initializing userID in the while--read loop:

while(objDR.Read()){
userFound = "yes";
userID = objDR.GetString(0);
}

Marcie


Yes it was because I needed to intialize userID,

Thanks

void login(Object s, EventArgs e){
int[] userInfo = new int[2];
int strAuthenticate;

userInfo = Authenticate(username.Text, password.Text);
strAuthenticate = userInfo[0];
if(strAuthenticate == 1){
//creating a cookie to store user info
FormsAuthenticationTicket objTicket;
HttpCookie objCookie;
objTicket = new FormsAuthenticationTicket(1, username.Text, DateTime.Now, DateTime.Now.AddMinutes(240), false, userInfo[1].ToString());
objCookie = new HttpCookie(".ASPXAUTH");
objCookie.Value = FormsAuthentication.Encrypt(objTicket);
Response.Cookies.Add(objCookie);

Response.Redirect("logedIn.aspx");
}
else{
lblLogin.Text = "INCORRECT USER NAME AND/OR PASSWORD";
}
}

int[] Authenticate(string strUsername, string strPassword){
OleDbConnection objConn = new OleDbConnection(ConfigurationSettings.AppSettings["backupDataB"]);
OleDbCommand objCmd;
OleDbDataReader objDR;

int userFound = 0;
int userID = 0;
int[] userInfo = new int[2];

objCmd = new OleDbCommand("SELECT * FROM users WHEREemail=@.strUsername ANDPassword=@.strPassword", objConn);
//get userID from this query and store it in a ticket
objCmd.Parameters.Add("@.strUsername", strUsername);
objCmd.Parameters.Add("@.strPassword", strPassword);

objConn.Open();
objDR = objCmd.ExecuteReader();
//"Read" reads each line that is returned from the datareader it starts one above the first record
//if the data is there it will return true if not it will return false. Here it is only examining to see
//if the datareader can read one line. If it can the record does exsit if it can't it means the reader
//returned nothing.
while(objDR.Read()){
userFound = 1;
userID = objDR.GetInt32(0);
}
objDR.Close();
objConn.Close();

userInfo[0] = userFound;
userInfo[1] = userID;

return userInfo;
}