Print Page | Close Window

Assigning data to a Parameter?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=18159
Printed Date: 28 March 2026 at 6:01am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Assigning data to a Parameter?
Posted By: Arkelias
Subject: Assigning data to a Parameter?
Date Posted: 26 January 2006 at 10:25pm

I am trying to insert a record into a database, and am having a lot of trouble getting the data from the text boxes I created to bind to the Parameters.  Anyone have any idea how I can get the text property of a text box to match up with a parameter so I can assign it to a field?  Thus far all that happens is I add a blank record and the strings in the text boxes are completely ignored...

Below is the code I have so far:
 

<Script runat="server">

Private Sub InsertBorrower(ByVal Source As Object, ByVal e As EventArgs)

'Dim Social_Security_Number As Parameter

'Social)Security_Number =

'Social_Security_Number.DefaultValue = txtSocial.Text

SqlDataSource1.Insert()

End Sub

</Script>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>"

DeleteCommand="DELETE FROM [Borrower] WHERE [Social Security Number] = @Social_Security_Number"

InsertCommand="INSERT INTO [Borrower] ([First Name], [Last Name], [Middle Name], [Social Security Number], [Current Address], [Co/Main Borrower], [Current Street Address], [Current City], [Current State], [Current Zip], [Income]) VALUES (@First_Name, @Last_Name, @Middle_Name, @Social_Security_Number, @Current_Address, @column1, @Current_Street_Address, @Current_City, @Current_State, @Current_Zip, @Income)"

ProviderName="<%$ ConnectionStrings:DatabaseConnectionString1.ProviderName %>"

SelectCommand="SELECT [First Name] AS First_Name, [Last Name] AS Last_Name, [Middle Name] AS Middle_Name, [Social Security Number] AS Social_Security_Number, [Current Address] AS Current_Address, [Co/Main Borrower] AS column1, [Current Street Address] AS Current_Street_Address, [Current City] AS Current_City, [Current State] AS Current_State, [Current Zip] AS Current_Zip, [Income] FROM [Borrower]"

UpdateCommand="UPDATE [Borrower] SET [First Name] = @First_Name, [Last Name] = @Last_Name, [Middle Name] = @Middle_Name, [Current Address] = @Current_Address, [Co/Main Borrower] = @column1, [Current Street Address] = @Current_Street_Address, [Current City] = @Current_City, [Current State] = @Current_State, [Current Zip] = @Current_Zip, [Income] = @Income WHERE [Social Security Number] = @Social_Security_Number">

<InsertParameters>

<asp:Parameter Name="First_Name" Type="String" />

<asp:Parameter Name="Last_Name" Type="String" />

<asp:Parameter Name="Middle_Name" Type="String" />

<asp:Parameter Name="Social_Security_Number" Type="Int16" DefaultValue= txtSocial.text />

<asp:Parameter Name="Current_Address" Type="String" />

<asp:Parameter Name="column1" Type="String" />

<asp:Parameter Name="Current_Street_Address" Type="String" />

<asp:Paramet




Replies:
Posted By: michael
Date Posted: 27 January 2006 at 4:11pm
You don't need to redefine the parameters just use:

Protected Sub InsertBorrower(ByVal sender As Object, ByVal e As System.EventArgs)
   SqlDataSource1.InsertParameters.Item("First_Name").DefaultValue = txtFirst.Text
   SqlDataSource1.InsertParameters.Item("Last_Name").DefaultValue = txtLast.Text
   SqlDataSource1.InsertParameters.Item("Middle_Name").DefaultValue = txtMiddle.Text
    'and so on
   SqlDataSource1.Insert()
End Sub


-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Arkelias
Date Posted: 27 January 2006 at 4:33pm
You sir are a god!  Thanks for the help!


Posted By: davidshq
Date Posted: 05 February 2006 at 6:06am
Ackk...And that was a question to which I knew the answer to. Bad luck for me. I am never fast enough.
David.


-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net