 |
| ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 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
|
|
|
|

December 21st, 2006, 01:49 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
My bad I already changed that. I have no clue on how to do this or if I'm going about it in the correct way. I have a text box named txtZip where the user enters their zip code to find a sales rep within their area. When the user clicks the image button it will send the paramater zip to a stored function table which returns name, address, city, state, zip, phone and email. This is what I have but I'm so lost.
<asp:TextBox
ID="txtZipCode"
runat="server" OnTextChanged="txtZipCode_TextChanged" />
<asp:RequiredFieldValidator
ControlToValidate="txtZipcode"
Text="Required"
runat="server" />
<asp:ImageButton
OnClick="Login_Click"
Runat="Server"
ImageUrl="images/button_submit.gif"
AlternateText="Find Representative" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="bla"
SelectCommand="SELECT * FROM here('@CustomerZip')" />
<SelectParameters>
<asp:ControlParameter ControlID="txtZipCode" Name="custzip" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Name"
DataSourceID="SqlDataSource1" Height="92px" OnPageIndexChanging="DetailsView1_PageIndexChangin g"
Width="496px" ForeColor="#FFFFFF">
<Fields>
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="Zip" HeaderText="Zip" SortExpression="Zip" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
</Fields>
</asp:DetailsView>
Instead of Login_Click for image what do I put?
|
|

December 21st, 2006, 02:00 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think your code is more complex than necessary. You don't have to trigger an event in server code; all you need to do is have a control that causes a post back. The following should work (if you change the connection string and the SQL statement:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:YourConn%>"
SelectCommand="SELECT * FROM [ExifData] WHERE ([Id] = @Id)">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="Id"
PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="Id"
DataSourceID="SqlDataSource1">
...
</asp:FormView>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
This code performs a SELECT * FROM a table called ExifData with an Id column. However, the same principle applies to your own data structure.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

December 21st, 2006, 02:03 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar I'll give it a shot.
|
|

December 21st, 2006, 04:23 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Something isn't right.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%ConnectionStrings:constring%>"
SelectCommand="SELECT * FROM @retSalesRep WHERE ([Zip] = @CustomerZip)" />
<SelectParameters>
<asp:ControlParameter ControlID="txtZipCode" Name="Zip" PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="Zip" DataSourceID="SqlDataSource1" >
<ItemTemplate>
<table>
<tr><td>
Name:
</td><td>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' />
</td></tr>
<tr><td>
Address:
</td><td>
<asp:Label ID="lblAddress" runat="server" Text='<%# Eval("Address") %>' />
</td></tr>
</table>
</ItemTemplate>
</asp:FormView>
CREATE FUNCTION dbo.fn_salesrep_lookup_custzip(@CustomerZip CHAR(6))
RETURNS @retSalesRep TABLE
(
-- Columns returned by the function
Name nvarchar(50) PRIMARY KEY NOT NULL
,Address nvarchar(50) NULL
,City nvarchar(50) NULL
,State nvarchar(50) NULL
,Zip nvarchar(50) NULL
,Phone nvarchar(50) NULL
,email nvarchar(50) NULL
)
AS
BEGIN
DECLARE
@Name nvarchar(50)
,@Address nvarchar(50)
,@City nvarchar(50)
,@State nvarchar(50)
,@Zip nvarchar(50)
,@Phone nvarchar(50)
,@email nvarchar(50);
-- Get contact information
SELECT
@Name =LTRIM(RTRIM(T1.[SM-NAME]))
,@Address =LTRIM(RTRIM(T1.[SM-ADDRESS1]))+
CASE
WHEN ISNULL(T1.[SM-ADDRESS2],'')='' THEN ''
ELSE ', '+LTRIM(RTRIM(T1.[SM-ADDRESS2]))
END
,@City =LTRIM(RTRIM(T1.[SM-CITY]))
,@State =LTRIM(RTRIM(T1.[SM-STATE]))
,@Zip =CASE
WHEN LEN(LTRIM(RTRIM(T1.[SM-ZIP])))=6 AND LEFT(LTRIM(T1.[SM-ZIP]),1)='0' THEN RIGHT(RTRIM(T1.[SM-ZIP]),5)
ELSE LTRIM(RTRIM(T1.[SM-ZIP]))
END
,@Phone =LTRIM(RTRIM(T1.[SM-PHONE]))
,@email ='email not yet available'
FROM dbo.SalesRep T1
INNER JOIN dbo.SalesRepCustomerZip T2 ON T1.[SM-NBR]=T2.[SM-NBR]
WHERE
CASE
WHEN LEN(LTRIM(RTRIM(T2.ZIP)))=6 AND LEN(LTRIM(RTRIM(@CustomerZip)))=6 THEN LTRIM(RTRIM(T2.ZIP))
WHEN LEN(LTRIM(RTRIM(T2.ZIP)))=6 AND LEFT(LTRIM(T2.ZIP),1)='0' THEN RIGHT(RTRIM(T2.ZIP),5)
ELSE LTRIM(RTRIM(T2.ZIP))
END
=@CustomerZip;
-- Return the information to the user
IF @CustomerZip IS NOT NULL AND @Name IS NOT NULL
BEGIN
INSERT @retSalesRep
SELECT @Name, @Address, @City, @State, @Zip, @Phone, @email;
END;
RETURN;
END;
GO
I'm getting this error
Server Error in '/' Application.
--------------------------------------------------------------------------------
Format of the initialization string does not conform to specification starting at index 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
System.Data.Common.DbConnectionOptions.GetKeyValue Pair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +1242
System.Data.Common.DbConnectionOptions.ParseIntern al(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +128
System.Data.Common.DbConnectionOptions..ctor(Strin g connectionString, Hashtable synonyms, Boolean useOdbcRules) +102
System.Data.SqlClient.SqlConnectionString..ctor(St ring connectionString) +52
System.Data.SqlClient.SqlConnectionFactory.CreateC onnectionOptions(String connectionString, DbConnectionOptions previous) +24
System.Data.ProviderBase.DbConnectionFactory.GetCo nnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +125
System.Data.SqlClient.SqlConnection.ConnectionStri ng_Set(String value) +56
System.Data.SqlClient.SqlConnection.set_Connection String(String value) +4
System.Web.UI.WebControls.SqlDataSourceView.Execut eSelect(DataSourceSelectArguments arguments) +138
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +17
System.Web.UI.WebControls.DataBoundControl.Perform Select() +149
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +70
System.Web.UI.WebControls.FormView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +82
System.Web.UI.WebControls.FormView.EnsureDataBound () +163
System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
|
|

December 21st, 2006, 04:29 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You declare the param for the ODS as type Int (probably copied from my example) yet the function uses a CHAR(6). That's probably not correct.
And what exactly does the function do? Isn't this something that can be done with a stored procedure?
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

December 21st, 2006, 04:35 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It is a stored procedure I just attached it for reference. I should have stated that. Sorry :)
|
|

December 21st, 2006, 05:10 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I tried taking out the Type="Int32" but got the same error as above. Then I tried adding Type="CHAR" but got the same result.
|
|

December 21st, 2006, 05:13 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If I were you, I'd try it with a simple stored procedure (not a function) first. Do a simple SELECT with one parameter. Then see if that works, and work from there....
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

December 21st, 2006, 05:21 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sounds good. Thanks for all your help. I hope I wasn't a big pain. :)
|
|
 |