mssql funktioniert jetzt
This commit is contained in:
parent
0bc404c6c1
commit
8983561a2b
@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
||||||
|
|
||||||
namespace ProgrammList.sql {
|
namespace ProgrammList.sql {
|
||||||
internal class Mssql {
|
internal class Mssql {
|
||||||
@ -66,11 +64,23 @@ namespace ProgrammList.sql {
|
|||||||
internal void checkTableExists() {
|
internal void checkTableExists() {
|
||||||
Open();
|
Open();
|
||||||
var command = Connection.CreateCommand();
|
var command = Connection.CreateCommand();
|
||||||
command.CommandText = "IF OBJECT_ID('list', 'U') IS NOT NULL BEGIN PRINT '0' END ELSE BEGIN PRINT '1' END";
|
command.CommandText = "select case when exists (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'prgmlist' AND TABLE_NAME = 'list') then 1 else 0 end";
|
||||||
var returncode = command.ExecuteScalar();
|
var returncode = command.ExecuteScalar();
|
||||||
if (returncode != null && returncode.ToString() == "1") {
|
if (returncode != null) {
|
||||||
|
int rc;
|
||||||
|
bool convertingResult = Int32.TryParse(returncode.ToString(), out rc);
|
||||||
|
|
||||||
|
if (!convertingResult) {
|
||||||
|
throw new FormatException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc > 0) {
|
||||||
Console.WriteLine("Creating table...");
|
Console.WriteLine("Creating table...");
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
var cols = string.Join(" VARCHAR(255),", valuenames);
|
var cols = string.Join(" VARCHAR(255),", valuenames);
|
||||||
cols = cols + " Varchar(255)";
|
cols = cols + " Varchar(255)";
|
||||||
command.CommandText = "CREATE TABLE list (" + cols + ")";
|
command.CommandText = "CREATE TABLE list (" + cols + ")";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user