//Executes a procedure with parameters that returns a table public DataTable executeFuncTable(String p_funcName, List <sqlParameter> p_params) { String functionString = createTableFuncString(p_funcName, p_params); SqlCommand cmd = new SqlCommand(functionString, this.m_cnx); cmd.CommandType = CommandType.Text; //Adding the parameters received as arguments to the parameters array of the SqlCommand for (int i = 0; i < p_params.Count; i++) { sqlParameter p = p_params.ElementAt(i); SqlParameter param = new SqlParameter(); param.ParameterName = p.Name; int paramValue = 0; if (!(Int32.TryParse(p.Value, out paramValue))) { param.Value = p.Value; } param.Value = paramValue; cmd.Parameters.Add(param); } DataTable returnTable = new DataTable(); this.m_cnx.Open(); SqlDataReader dataReader = cmd.ExecuteReader(); returnTable.Load(dataReader); this.m_cnx.Close(); return(returnTable); }
//Executes a scalar Function with parameters public int executeScalFunc(String p_funName, List <sqlParameter> p_params) { String functionString = createFuncString(p_funName, p_params); SqlCommand cmd = new SqlCommand(functionString, this.m_cnx); //Adding the parameters received as arguments to the parameters array of the SqlCommand for (int i = 0; i < p_params.Count; i++) { sqlParameter p = p_params.ElementAt(i); SqlParameter param = new SqlParameter(); param.ParameterName = p.Name; int paramValue = 0; if (!(Int32.TryParse(p.Value, out paramValue))) { param.Value = p.Value; } param.Value = paramValue; cmd.Parameters.Add(param); } this.m_cnx.Open(); int resultInt = Convert.ToInt32(cmd.ExecuteScalar()); this.m_cnx.Close(); return(resultInt); }
public int temp() { List <sqlParameter> parameters = new List <sqlParameter>(); sqlParameter param = new sqlParameter(); param.Name = "@CharID"; param.Value = "1"; parameters.Add(param); return(m_executer.executeScalFunc("dbo.fnGetCharGoldPiece", parameters)); }
public DataTable getCurrentStats(int p_charID) { List <sqlParameter> parameters = new List <sqlParameter>(); sqlParameter param = new sqlParameter(); param.Name = "@CharID"; param.Value = p_charID.ToString(); parameters.Add(param); DataTable dataTable = m_executer.executeFuncTable("dbo.fnGetCharFromID", parameters); return(dataTable); }
//Parses a procedure string and returns the result private String createProcString(String p_procName, List <sqlParameter> p_params) { String procString = ""; procString = p_procName; for (int i = 0; i < p_params.Count; i++) { sqlParameter p = p_params.ElementAt(i); procString += p.Name; if (i != p_params.Count - 1) { procString += ", "; } } return(procString); }
//Parses a function string for table function and returns the result private String createTableFuncString(String p_funName, List <sqlParameter> p_params) { String funcString = ""; funcString = "SELECT * FROM " + p_funName + "("; for (int i = 0; i < p_params.Count; i++) { sqlParameter p = p_params.ElementAt(i); funcString += p.Name; if (i == p_params.Count - 1) { funcString += ")"; } else { funcString += ", "; } } return(funcString); }