Thanks Bill I’ll see how it goes with the SharePoint stuff
Cheers Craig From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Bill Chesnut (Lists) Sent: Wednesday, 11 August 2010 5:14 PM To: ozMOSS Subject: Re: executing sql procedure Craig, I have put your code into Vs2008 and fixed a couple of the issues with it: void GenerateDefaults(object sender, EventArgs e) { string connString = "Data Source=bilbo;User ID=sa;Password=XXXXX;Initial Catalog=wss_content_custom;"; using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connString)) { System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); cmd.CommandText = "[wss_content_custom].[dbo].[GenerateDefaultModels]"; cmd.CommandType = System.Data.CommandType.StoredProcedure; try { connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } catch (Exception ex1) { Console.WriteLine(ex1.ToString()); } } } Not sure on the sharepoint stuff, but the code is not correct from a VS point of view. Bill Chesnut BizTalk Server MVP Melbourne, Australia ________________________________ From: Craig Stevens [mailto:cr...@catalyst.net.au] To: ozMOSS [mailto:ozm...@ozmoss.com] Sent: Wed, 11 Aug 2010 15:57:08 +1000 Subject: executing sql procedure Hi all, I’m trying to allow users to create a default setoff data in an sql database for a given product. I’d like to have a form button press that generates it. I’m using SharePoint Destroyer 2007 I’ve added an asp button <asp:Button runat="server" Text="Button" id="Button1" onclientclick="GenerateDefaults" /> I’ve also added the flowing function near the bottom of the aspx page <script runat="server"> void GenerateDefaults(object sender, EventArgs e) { using System.Data.SqlClient; string connString ="Data Source=bilbo;User ID=sa;Password=XXXXX;Initial Catalog=wss_content_custom;" ; using(SqlConnection connection = new SqlConnection(connString)) SqlCommand cmd = new SqlCommand(); cmd.text="[wss_content_custom].[dbo].[GenerateDefaultModels]"; try { connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); }catch (Exception e) { Console.WriteLine(e.ToString()); } } The error I get is “An error occurred during the compilation of the requested file, or one of its dependencies. Syntax error, '(' expected” I have no idea where to begin for this. If anybody has a solution, or a better way to execute a stored procedure in an sql databse from a sharepoint page I’d be glad to hear it Cheers Craig
_______________________________________________ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss