Showing posts with label sqldatasource. Show all posts
Showing posts with label sqldatasource. Show all posts

Sunday, March 11, 2012

a SqlDataSource can execute two InsertCommand?

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.

Thursday, March 8, 2012

A simple insert

Hi,

how do I perform a simple insert command?

I dont need the SQL syntax, just how do i do it using VS2005.

using SqlDataSource, for some reason, after writing the insert sentence, the "next" button remains gray.

i am using VS2005 and sql server.

Thank you.

Have you defined a SELECT statement? It seems you have to always have a SELECT statement when using the VS SqlDataSource configuration wizard.|||Thanks!

Friday, February 24, 2012

A question about SqlDataSource

In a web appliction, I want to use sqldatasource and I also want to hide the SQL script used in sqldatasource in the DAL, is anyboyd can tell me how to achieve the target? thanksObjectDataSource?

Thursday, February 16, 2012

a problem in sqldatasource

How I can know my sqldatasourse found any record or not I dont want to use datalist or another data table .and how I can put each feild that sqldatasource found on a string object( ineed just one record that sqldatasource found.)
I need a code that on page load automaticly goto another pageAngel

In the data source's Selected handler ther is a param SqlDataSourceStatusEventArgs e, e.AffectedRows will expose how many rows are selected~

But since you don't bind it to a data present control, and you have only one row to select, why not useDataReader? Manipulating data isn't data source's job, but DataSet and DataReader are much better at that~

And to goto another page, the simplest way is Response.Redirect() or Server.Transfer()