Last post Oct 10, 2012 05:13 PM by limno
Oct 10, 2012 01:27 PM|AlphaWhelp|LINK
I'm trying to write a program that does three SQL operations at the same time, Update, Insert, and Delete, and so I've made a datasource that uses 3 stored procedures, one for each action, and then created a button that calls all three of those procedures
via .Update() .Insert() and .Delete()
only it's not working
Here is my code in the button.Click event it keeps telling me to use New like the parameter doesn't exist (but it does)
dsUpdateDetails.UpdateParameters("@Media_ID").DefaultValue = CType(lblMedia_ID.Text, Integer)
dsUpdateDetails.UpdateParameters("@Title").DefaultValue = txtTitle.Text
dsUpdateDetails.UpdateParameters("@Format").DefaultValue = txtFormat.Text
dsUpdateDetails.UpdateParameters("@Event").DefaultValue = txtEvent.Text
dsUpdateDetails.UpdateParameters("@Date").DefaultValue = cldDate.SelectedDate
dsUpdateDetails.UpdateParameters("@Speakers").DefaultValue = txtSpeakers.Text
dsUpdateDetails.UpdateParameters("@GeneralAccess").DefaultValue = chkGeneralAccess.Checked
dsUpdateDetails.UpdateParameters("@Duration").DefaultValue = txtDuration.Text
Oct 10, 2012 01:35 PM|UstesG|LINK
why dont you make 1 stored proc, pass in the values then do your CRUD operation in t-sql in the proc?
Oct 10, 2012 01:38 PM|spapim|LINK
Try putting the code in the OnUpdating event of SQLDataSource. Ex:
protected void dsUpdateDetails_Updating(object sender, SqlDataSourceCommandEventArgs e)
e.Command.Parameters["@Media_ID"].Value = CType(lblMedia_ID.Text, Integer)
Hope this helps.
Oct 10, 2012 02:07 PM|AlphaWhelp|LINK
I fixed it. the problem was the SqlDataSource cut off all the @ from the parameter names when it auto generated the parameter fields in the ASP.NET code, all I did was change @Media_ID to just Media_ID et al and it worked fine.
Thanks for everyone's suggestions.
Oct 10, 2012 05:13 PM|limno|LINK
Whether you should have @ sign for your parameters is depending on what kind of event you are using these parameters. In your button click event, you don't need it but if it were from a SQLDataSource event, you must include the @ sign in front of these parameters'