Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Programatically Create a Stored Procedure...?
Message
De
19/05/2006 20:47:48
 
 
À
19/05/2006 17:03:56
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
VB.NET 1.1
Divers
Thread ID:
01122634
Message ID:
01123714
Vues:
21
>Thanks, Bonnie. I knew this should work, I just don't do .NET often enough to post the syntax off the top of my head.<

Hah! You think I have all this syntax in my head?!?! <g>

Actually, a lot of it I *do* know off the top of my head (nowhere *near* everything of course <g>), but I keep a little test app for just this purpose ... to copy/paste sample code that I *know* will work (and if I *do* post code that's just "off the top of my head", then I'll mention that it's untested and posted just to illustrate the concept).


~~Bonnie



>
>>Actually, Ben, Fred is right ... maybe I should have replied to him yesterday to give him an "attaboy" when I saw his post. Here's how you would do this:
>>
>>string ConnString = "server=(local);uid=sa;pwd=";
>>
>>SqlConnection oConn = new SqlConnection(ConnString);
>>SqlCommand sc = new SqlCommand("use MyDataBase", oConn);
>>oConn.Open();
>>sc.ExecuteNonQuery();
>>
>>sc.CommandText = "select * from MyTable";
>>SqlDataAdapter da = new SqlDataAdapter(sc);
>>
>>DataSet ds = new DataSet();
>>da.Fill(ds);
>>oConn.Close();
>>
>>
>>The trick is to open the connection and "use" your database, then keeping the same connection, do whatever else you need to do.
>>
>>~~Bonnie
>>
>>
>>>>You don't need to connect to your database in your connection string, just to your server. You can then connect to the appropriate database using the "USE yourdatabase" command via a SQLEXEC. This way, you can change databases using the same connection.
>>>
>>>Actually, as it was stated by Borislav and Bonnie earlier in this thread...one has to use the database name in the connection string (Initial Catalog=...) otherwise it won't work. It you notice in my original posting, I mentioned that I tried using the "USE " SQL command and it came back with an error stating that CREATE PROCEDURE has to be the first executing statement in a batch.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform