Don't define your class variables and function as static. When you define them as static, they are not members of the instance of the class object that is created by the calling program. That is most likely the cause for your values not coming out right. There's a good explaination on static from C# Help (http://www.csharphelp.com/archives/archive148.html).
If you don't need to have the caller create an instance of this class, then remove the constructor and the class variables. Just have the values passed in to your method that issues the SQL call. You didn't mention what type of code is calling this function: managed (.NET) or unmanaged (non-.NET). ...Glenn On Tue, Jan 20, 2009 at 5:26 AM, Chris <[email protected]> wrote: > > Hi all, > > Very new to this game so Im probably making a simple yet fundamental > mistake. > > Im trying to pass into C# (2008 Express) 2 (float) variables from > another program, and use these to kick off a stroed proc on a server. > The server end of things is fine, but Im struggling to get the > variables to pass in. Its either the way Im declaring and setting the > variables, or the way im building the .dll file. I need the .dll file > as I have another program which calls C# with the variables. Any > Ideas? > > Thanks in advance > > Chris > > using System; > using System.Collections.Generic; > using System.Text; > using System.Data; > using System.Data.SqlClient; > > namespace ExecuteStoredProcedure > { > public class Program > { > private static double dLong; > private static double dLat; > > public Program(double X, float Y) > { > dLong = X; > dLat = Y; > } > > //static void Main(string[] args) > public static void Boundary() > { > > SqlConnection conn = new SqlConnection(); > try > { > conn.ConnectionString = "integrated security=SSPI;data > source=ServerName;" + > "persist security info=False;initial > catalog=DatabaseName"; > conn.Open(); > Console.WriteLine("Connection successful"); > } > catch (Exception ex) > { > Console.WriteLine(ex.Message); > return; > } > > SqlCommand db_cmd = new SqlCommand("dbo.uspStoredProc", > conn); > db_cmd.CommandType = CommandType.StoredProcedure; > db_cmd.Parameters.Add(new SqlParameter("@X", > ExecuteStoredProcedure.Program.dLong)); > db_cmd.Parameters.Add(new SqlParameter("@Y", > ExecuteStoredProcedure.Program.dLat)); > try > { > db_cmd.ExecuteNonQuery(); > Console.WriteLine("Data write successful"); > Console.Read(); > } > catch { Console.WriteLine("Error"); } > conn.Close(); > } > } > } >
