1

Im having trouble trying to create and set some sqlupdate parameters, my code below will hopefully be self explaniatory.

vis studio is not happy with my PArams being in the datasource at the mo

Thanks for any advice chaps

protected void btnSave_Click(object sender, EventArgs e)
{
    List<SqlParameter> Params = new List<SqlParameter>();
    Params.Add(new SqlParameter("@ID", hidID.Value));
    Params.Add(new SqlParameter("@MachineName", txtMachine.Text));
    Params.Add(new SqlParameter("@AssetNo", txtAssetNo.Text));
    Params.Add(new SqlParameter("@ID", hidID.Value));

    dsEquipment.UpdateParameters.Add(Params);

    if (strMode == "edit")
    {
        dsEquipment.Update();
    }
    else if (strMode == "insert")
    {
        dsEquipment.Insert();
    }
    else
    {
        return;
    }


}
AlexW
  • 2,843
  • 12
  • 74
  • 156
  • Is there a compelling reason you're not just configuring these in the markup? – Mike Perrenoud Apr 12 '13 at 14:53
  • Because the values of txtName.Text are all set programatically so where i would normally use Value='<%# Bind("UserID") %>' i cant can i? basically i have a list view and im using a control as a form within that list view so first my listview populates the usercontrol then i need to update the data, so this is the way i thought would be right? – AlexW Apr 12 '13 at 15:05
  • Basically i have a big form for edit/insert itemtemplate and they're nearly the same, so im using a control for the two – AlexW Apr 12 '13 at 15:21

1 Answers1

0

Before I delete try

dsEquipment.UpdateParameters = Params;

or

dsEquipment.UpdateParameters.Add(new SqlParameter("@ID", hidID.Value));
dsEquipment.UpdateParameters.Add(new SqlParameter("@MachineName", txtMachine.Text));

UpdateParameters is from System.Web.UI.WebControls
And this does not look like a web app
SqlDataSource.UpdateParameters

Try using SQLcommand or something from System.Data.SqlClient

SqlCommand.Parameters Property

SqlCommand command = new SqlCommand(commandText, connection);
command.Parameters.Add("@ID", SqlDbType.Int);
command.Parameters["@ID"].Value = customerID;
paparazzo
  • 44,497
  • 23
  • 105
  • 176
  • It is a web app yeah... I need to run a stored procedure to update a record, I have a sqldatasource in my aspx page and i have a connection string in my webconfig, how would i get this to work? thanks – AlexW Apr 12 '13 at 16:02
  • Then never mind. I will delete. You should tag the ASP.NET – paparazzo Apr 12 '13 at 16:07
  • i dont know what to put for commandtext and connection? :S sorry – AlexW Apr 12 '13 at 16:24