views:

106

answers:

1

I have a sqldatasource connection in whose parameters, the insert parameter is set as

INSERT INTO [user_info] ([firstname], [lastname], [age]) VALUES (@firstname, @lastname, @age)

Now i understand @firstname, @lastname, @age are the parameters to which i set them the value.

I'm databinding it with a formview, which automatically binds the textbox in the insertitemtemplate with the columns Firstname, lastname and age respectively. For instance the FirstName Text box has the following property.

 <asp:TextBox ID="firstnameTextBox" runat="server" Text='<%# Bind("firstname") %>' />

Now my doubt is that, the @firstname variable how is bound with the firstname field. I have not explicitly used the binding anywhere. Say tomorrow i want to rename the insert query as

INSERT INTO [user_info] ([firstname], [lastname], [age]) VALUES (@fn, @ln, @ag)

where and all i will have to make changes inorder to bind @fn with FirstName and so on.

Hope my question is clear.

A: 

Short Answer: changing your parameter names won't cause a ripple effect. Changing your column name will.

Detailed Answer: Databinding with Bind (and Eval) in this case applies to the column name of your SQL table, not the parameter name. If you were to start using the 2nd INSERT statement with @fn your Bind would continue to use "firstname" without needing to change.

However, if you updated your table and renamed the "firstname" column to "fn" this is no longer the case and you now have 2 choices:

  1. Update all Bind() calls to use "fn" instead of "firstname" - this would require many changes if it occurs in many places.
  2. Update your SELECT statement (or stored procedure) to alias the fn column as firstname (ie. SELECT [fn] as firstname, ... other columns ... FROM [user_info]) - this is advantageous since the change happens at the source and doesn't affect existing binding to "firstname," which means making a change in only one place.
Ahmad Mageed