View Single Post
Old 01-03-2005, 08:43 PM   #10
NrmMyth
Hero Gamer

 
Join Date: Jan 2005
Location: ,
Posts: 454
Default

Quote:
Originally posted by aaberg+Mar 1 2005, 09:44 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (aaberg @ Mar 1 2005, 09:44 AM)</td></tr><tr><td id='QUOTE'>
Quote:
Originally posted by NrmMyth@Feb 25 2005, 05:08 PM
Quote:
Originally posted by aaberg@Feb 23 2005, 12:55 PM
<!--QuoteBegin-Unknown Hero
Quote:
Quote:
@Feb 23 2005, 12:05 AM
You can chalenge me! I'm in! k:*

Ok. Here is my challenge.

Make a function, which is able to launch any stored procedure in a database, that doesn't return any queries. :evil: The prototype is shown below.

public void executeStoredProc(string storedProcedureName, string[] parameterName, string[] parameterValue);

The prototype is only a suggestion. You are free to make your own. You may program it in whatever langauage you would like.

If it is too easy, just tell me, and I figure out something harder. :Jesus:

If I have to post the answer, it will be in C#.net

//First include your header with wanted stored proc

#include "yourheader.h"

//This is your function

void executeproc(void *procname(),char *parametername,char *parametervalue,int sizeofparameter)
{ void value,parameter;

if(sizeofparameter==sizeof(int))
{ sscanf("%d",&(int)parameter);
(int)value=parameter;
}
else if(sizeofparameter==sizeof(float))
{ sscanf("%f",&(float)parameter);
(float)value=parameter;
}
.
.
.
//And like this you check type and switch the void in needed type.

procname(value);
}

I did'n test it. So expect some errors.

I know it is not a very good procedure becouse i operates only with one parameter of that proc. you have stored.
And I don't know how to use function with unknown number of parameters (function(blah,blah,...)).

PS: I see you program in c# ,could you explain a little, difrences from ordinary c/c++.
I do c.
To give the function an unknown number of parameters, you need to work with arrays. Below I have written a way to solve the problem in C#.

If you open a new thread dedicated to talk about the difference between C/C++ and C#, I will gladly post.

public void executeStoredProc(string storedProcedureName, string[] parameterName, string[] parameterValue)
{
OleDbConnection objConn = new OleDbConnection("Connectionstring");
//The connectionstring depends on, which database you are using.

OleDbCommand objCommand = objConn.CreateCommand();

objCommand.CommandType = CommandType.StoredProcedure;
objCommand.CommandText = storedProcedureName;

for (int index = 0; index < parameterName.Length; index++)
{
objCommand.Parameters.Add(parameterName[index], parameterValue[index];
}

try
{
objConn.Open();

objCommand.ExecuteNonQuery();
}
catch
{
throw new Exception("Error while executing procedure");
}
finally
{
objConn.Close();
}
}

This should work.
[/b][/quote]
Ok this is great but I don't understand a thing of object-oriented programing.
Supose I need more knowledge.
I won't open a tread becouse I don't know c++, and as I know a little c++ and c# are more diferent then ordinary c.
But thanks anyway. k:
__________________
Never mess with me when I have a cougar, Never!
NrmMyth is offline                         Send a private message to NrmMyth
Reply With Quote