| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

03-08-10, 09:24
|
|
Registered User
|
|
Join Date: Feb 2009
Location: Sweden
Posts: 19
|
|
Stored Procedure to solve this problem !!!
|
|
Hi there,
i have this code with c#.net, i need to use stored procedure to do the same work!!!
Code:
SqlCommand comm1;
SqlConnection conn1;
string connectionString1 = ConfigurationManager.ConnectionStrings["DBConnectionString1"].ConnectionString;
conn1 = new SqlConnection(connectionString1);
string sqlcomm1 = "INSERT INTO customer (name, firstname, tele, mobil, fax, email, personno)" +
"SELECT DISTINCT contactperson, Name, Tele, Mobil, Fax, email, PersonNo FROM tem5"+" WHERE (Seid ='" + susid + "')";
comm1 = new SqlCommand(sqlcomm1, conn1);
conn1.Open();
comm1.ExecuteNonQuery();
conn1.Close();
what i need how to make the above sql statement with Insert, Select and Where as stored procedure ???
how i can call the stored procedure from c#.net programming to pass the "susid" ???
thanks alot in advance ...
|
|

03-08-10, 13:11
|
|
Registered User
|
|
Join Date: Jun 2004
Location: Long Island
Posts: 696
|
|
-- Usage exec usp_customer @Seid = 11
create procedure usp_customer
(@Seid int)
as
INSERT INTO customer (name, firstname, tele, mobil, fax, email, personno)
SELECT DISTINCT contactperson, Name, Tele, Mobil, Fax, email, PersonNo FROM tem5 WHERE (Seid = @Seid)
I think to exec, something like this:
SqlCommand comm1;
SqlConnection conn1;
string connectionString1 = ConfigurationManager.ConnectionStrings["DBConnectionString1"].ConnectionString;
conn1 = new SqlConnection(connectionString1);
string sqlcomm1 = "exec usp_customer @Seid = " + susid;
comm1 = new SqlCommand(sqlcomm1, conn1);
conn1.Open();
comm1.ExecuteNonQuery();
conn1.Close();
|
Last edited by PMASchmed; 03-08-10 at 13:16.
|

03-10-10, 07:45
|
|
Registered User
|
|
Join Date: Feb 2009
Location: Sweden
Posts: 19
|
|
|
|
Hi PMASchmed,
i don't know but it doesn't work!!!
any suggestion !!!
|
|

03-10-10, 17:59
|
|
Registered User
|
|
Join Date: Jun 2004
Location: Long Island
Posts: 696
|
|
Name the columns in the select to match the insert.
|
|

03-11-10, 04:57
|
|
Registered User
|
|
Join Date: Feb 2009
Location: Sweden
Posts: 19
|
|
yes, i'll try that ... thanks
|
|

03-11-10, 07:38
|
|
Registered User
|
|
Join Date: Sep 2001
Location: Chicago, Illinois, USA
Posts: 551
|
|
Quote:
Originally Posted by Abrahm75
Hi PMASchmed,
i don't know but it doesn't work!!!
any suggestion !!!
|
What do you mean that it doesn't work?
Can you create the stored procedure without error?
Did you test the stored procedure within itself?
Whenever I write a stored procedure, I use the following organization:
Code:
create procedure usp_customer
@Seid int
as
set nocount on
/* TEST SECTION
usp_customer @Seid=11 with recompile
declare @Seid int
set @Seid=11
--*/
INSERT
INTO customer
SELECT
DISTINCT
contactperson name
,Name firstname
,Tele
,Mobil
,Fax
,email
,PersonNo
FROM tem5
WHERE Seid=@Seid
If you wipe from the "declare" downward you can test your code and make sure the query itself is working.
Did you give the stored procedure execute permissions for the user who will be accessing the code?
__________________
Ken
Maverick Software Design
(847) 864-3600 x2
|
|

03-11-10, 08:50
|
|
World Class Flame Warrior
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
|
|
The line comment before your section end comment tag is a nifty idea. I'll definitely use that!
__________________
If it's not practically useful, then it's practically useless.
blindman
www.chess.com: "sqlblindman"
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|