Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Data.SqlTypes;
- using Microsoft.SqlServer.Server;
- public class Wynik
- {
- [Microsoft.SqlServer.Server.SqlProcedure]
- public static void wiersze(String tabela, out SqlInt32 ile)
- {
- try
- {
- ile = 0;
- SqlConnection conn = new SqlConnection("context connection=true");
- conn.Open();
- SqlCommand zap = new SqlCommand("SELECT count(*) FROM " + tabela, conn);
- SqlDataReader zapReader = zap.ExecuteReader();
- if (zapReader.HasRows)
- {
- zapReader.Read();
- ile = zapReader.GetInt32(0);
- }
- }
- catch (SqlException)
- {
- ile = -1;
- }
- }
- [SqlFunction(DataAccess = DataAccessKind.Read)]
- public static int? wiersze_f(SqlString tabela)
- {
- if (!String.IsNullOrEmpty(tabela.ToString()))
- {
- try
- {
- int? ile = 0;
- SqlConnection conn = new SqlConnection("context connection=true");
- conn.Open();
- SqlCommand zap = new SqlCommand("SELECT count(*) FROM " + tabela.ToString(), conn);
- SqlDataReader zapReader = zap.ExecuteReader();
- if (zapReader.HasRows)
- {
- zapReader.Read();
- ile = zapReader.GetInt32(0);
- }
- return ile;
- }
- catch (SqlException)
- {
- return -1;
- }
- }
- else return null;
- }
- }
Add Comment
Please, Sign In to add comment