hi everyone
i have a SqlDataSource
and i want execute two T-Sql (two InsertCommand)
but not success
How did i do this?
Thanks
1 Protected Sub SqlDataSource1_Inserted(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)Handles SqlDataSource1.Inserted
2 Dim SDSTempAs SqlDataSource =Nothing
3 Try
4 SDSTemp =New SqlDataSource(CnStr,"")
5 SDSTemp.InsertCommandType = SqlDataSourceCommandType.Text
6 SDSTemp.InsertCommand ="INSERT INTO Table1 (id,t1,t2) VALUES (@.id,@.t1,@.t2)"
7 Dim idAs String = e.Command.Parameters("@.id").Value.ToString
8 SDSTemp.InsertParameters.Add("id", id)
9 SDSTemp.InsertParameters.Add("t1",CType(FormView1.FindControl("TextBox1"), TextBox).Text)
10 SDSTemp.InsertParameters.Add("t2",CType(FormView1.FindControl("TextBox2"), TextBox).Text)
11 SDSTemp.Insert()
12
13 SDSTemp.InsertCommand ="INSERT INTO Table2 (id) VALUES (@.id)"
14
15 SDSTemp.InsertParameters.Add("id", id)
16
17 SDSTemp.Insert()
18 Catch exAs Exception
19 Message.Text = ex.Message.ToString
20 End Try
21 End Sub
22
you can use the ItemCommand Event and place your code in there. Here is a reference you can use:http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.itemcommand.aspx
The following link shows an quick example I made to help ya out some more also:http://forums.asp.net/thread/1692239.aspx
Hope this helps.
No comments:
Post a Comment