Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2009, 07:21 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default How to Pass Values From Previous Page

hi there i have this code
Code:
ProtectedSub button_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles button.Click
IfNot Page.PreviousPage IsNothingThen
Dim txtName As TextBox
txtName = CType(PreviousPage.FindControl("txtName"), TextBox)
EndIf
 
Dim conn AsNew SqlConnection(ConfigurationManager.ConnectionStrings("test").ConnectionString)
Dim sql As SqlCommand
sql += "INSERT INTO " & txtName.text & "(test) VALUES(' " & Me.ListBox1.SelectedItem & "');"
Dim Cmd AsNew SqlCommand(sql, conn)
Cmd.CommandType = CommandType.Text
Cmd.ExecuteNonQuery()
conn.Close()
 
 
Cmd.Parameters.Add("@Test", Data.SqlDbType.VarChar, 50).Value = Me.ListBox1.SelectedItem
 
conn.Open()
Cmd.ExecuteNonQuery()
 
conn.Close()
but it does not work ,
txtName is not declared ?

__________________
bx

Last edited by bex; January 12th, 2009 at 08:35 AM..
 
Old January 12th, 2009, 07:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hello.. You are trying to get txtname from previous page?? Well, you are looking for it in current page. Also in the first if clause, you are just looking if the previous page is not nothing, and you should be looking if it is nothing.

and I think you want to add txtcampaignname to the SQL.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old January 12th, 2009, 08:43 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

It is not that simple as it looks? in the previous page i have declared something like this
[code]
ProtectedSub btnCreateCampaign_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnCreateCampaign.Click
Dim s AsString
Dim l AsString
s = txtName.Text
l = s
While InStr(l, " ")
l = Replace(l, " ", "")
EndWhile
Dim conn AsNew SqlConnection(ConfigurationManager.ConnectionStrin gs("test").ConnectionString)
conn.Open()
Dim SQL AsString = "CREATE TABLE " & l & " (Name Nvarchar (50));"
SQL += "INSERT INTO " & l & "(Name) VALUES(' " & s & "');"
Dim Cmd AsNew SqlCommand(SQL, conn)
Cmd.CommandType = CommandType.Text
Cmd.ExecuteNonQuery()
conn.Close()
[/ccode]

u see the tabel is created dinamicly and i want to insert into the
ListBox1.SelectedValue into the table that is just created.

and when i click the btnCreateCampaign i get
Code:
Cannot insert the value NULL into column 'Name', table 'test.dbo.test1'; column does not allow nulls. INSERT fails.
The statement has been terminated.
__________________
bx

Last edited by bex; January 12th, 2009 at 08:47 AM..
 
Old January 13th, 2009, 07:24 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

I did manage to pass the values from previous page but now i have to insert some values into the table i use this
Code:
 
ProtectedSub AssignCT_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles AssignCT.Click
Dim s AsString
Dim l AsString
s = lblCampaignName.Text
l = s
While InStr(l, " ")
l = Replace(l, " ", "")
 
EndWhile
Dim conn AsNew SqlConnection(ConfigurationManager.ConnectionStrings("test").ConnectionString)
conn.Open()
Dim SQL AsString = "CREATE TABLE " & l & " (Name Nvarchar(50),Email Nvarchar(256),ContactBy Nvarchar(50),PictureTitle Nvarchar (50),Template Nvarchar (50),CampaignName Nvarchar (50));"
SQL += "INSERT INTO " & l & "(Template) VALUES(" & s & ");"
Dim Cmd AsNew SqlCommand(SQL, conn)
Cmd.CommandType = CommandType.Text
Cmd.ExecuteNonQuery()
conn.Close()
and i get this error
The name "test" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
lblCampaign.Text is : test test
__________________
bx





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass values from Aspx page to Flash Muthunagai.A ASP.NET 1.0 and 1.1 Professional 0 April 25th, 2007 11:43 PM
Pass values from Aspx page to Flash Muthunagai.A Excel VBA 0 April 25th, 2007 11:37 PM
Get values of asp controls on previous page GraceOriole ASP.NET 2.0 Professional 0 December 20th, 2006 11:35 PM
help me to pass the check box values to new page ansar BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 November 16th, 2004 06:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.