Showing posts with label webpage. Show all posts
Showing posts with label webpage. Show all posts

Wednesday, March 28, 2012

Help! T-SQL, Calling multiple stored procs?

I have to load a webpage table up with values from a database as such:

The Webpage Expects a Final result set of rows with 5 columns each built as below:

For each Row Returned by StoredProc1

Write Columns 1-3 = StoredProc2

Write Column 4 = StoredProc3

Write Column 5 = StoredProc4

Next Row


But I am not sure how to write the conditionals to CALL the stored procs i wrote and loop by a return value from StoredProc1.

Any help is much appreciated!

THANKS!

I would prefer to create separate stored proc with entire logic encapsulated within it, if I were you. Loops are fast and typical in client languages, but in SQL it's better not to be overused.|||So create just one big stored proc to do it all?
|||Yes. And calling stored procs from within stored procs is not so fast.|||

Can you be a little more specific about what each stored proc does? I mean, if it is a set of procs you are writing, then I doubt this is the best way to do it. I would be more inclined to write one stored procedure with one SELECT statement that joins 3 larger sets together (perhaps in temp tables) on the common value from a fourth set.

select *

from QueryFromSP1

outer join (QueryFromSP2) as QueryFromSP2
on QueryFromSP1.key = QueryFromSP2.key

...

The queries could be temp tables, or function calls, depending on the need, but a cursor like you have suggested will probably be a dog in performance (and not one of those really fast dogs either. Think hound dog on a hot Mississippi morning dogs.)

Monday, March 19, 2012

Help! Insert a record into SQL database with ASP.net and C#

I'm trying to make a website that people can upload file to the server, then the webpage will automatically insert the username and the file name into the database. I have thought about this for couple days but still got nothing. can some one help me?

can some one post a very simple aspx file that can insert a record to the sql database with C#? Not the code that generated by ASP.net 2.0!

I want to see how to access the database manually.

Thank you.

A quick example:

protected void Button1_Click(object sender, EventArgs e)
{
string connectionString = @."Data Source=Confute;Initial Catalog=AdventureWorks;Integrated Security=SSPI";

using (SqlConnection connection = new SqlConnection(connectionString))
{

SqlDataSource sds = new SqlDataSource(connectionString, "select * from Orders (where EmployeeID in (@.list))");


SqlCommand cmd = new SqlCommand("insert into t1 (name) select @.name", connection);

//add text of txtBox_Name as input parameter for the insert command
cmd.Parameters.Add("name", txtBox_Name.Text);

connection.Open();
cmd.ExecuteNonQuery();
}

}

|||It is really help! Thank you very much