2013-07-05 69 views
0

基本上,我有一个Gridview。我正在获取特定单元格的文本值并放入一个asp标签。如何通过Asp.net中的SqlDataSource存储过程参数将Int32输入发送到数据库

现在我想使用该标签的文本输入的存储过程上的SqlDataSource像这样

 <asp:SqlDataSource ID="AddressContactSource" 
      runat="server" 
      ConnectionString="<%$ ConnectionStrings:UACOrdersConnectionString %>" 
      SelectCommand="GetAddressContact" 
      SelectCommandType="StoredProcedure"> 
        <SelectParameters> 
         <asp:ControlParameter ControlID="Silver" 
          Name="@AccountID" 
          PropertyName="Text" 
          Type="Int32" DefaultValue="2624" /> 

        </SelectParameters> 
       </asp:SqlDataSource> 

的问题是,这并不工作,因为帐户ID(存储proceedure输入参数)是一个int32和Label的文本是一个字符串,因此它不会在与SqlDatasource绑定的Details视图中显示任何结果。

现在我有一个选择索引在放置单元格的gridview的codebehind中更改的方法。

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) 
    { 


     string temp = GridView1.Rows[1].Cells[5].Text; 
     Silver.Text = temp; 
     int temp2 = Convert.ToInt32(temp, 10); 
     Parameter p = new Parameter(); 
     p.Direction = ParameterDirection.Input; 
     p.Type = TypeCode.Int32; 
     p.Name = "@AccountID"; 
     AddressContactSource.SelectParameters.Add(p); 
     AddressContact.DataBind(); 
     updatepanel1.Update(); 
    } 

我的代码编译并且不会在调试中抛出任何异常。我知道这是接近,但参数没有一个构造函数接受一个int。 所以我不能添加它。那么,我该怎么做?

+0

我真的不知道参数类属于哪个名称空间,但是如果它与SqlParameter相同。你可以做p.Value = someInt; –

回答

1

您不需要参数名称以@开头(只有在存储过程输入参数从@@开始时才需要)。

另外我相信你不需要在SelectedIndexChanged处理程序中添加参数,只要你更新标签文本并且调用DataBind控制参数就应该自动获得新的值。

相关问题