
Well first of all we will make a Sql class.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class SqlWrapper
{
}
}
Code:
using System.Data.SqlClient;
Code:
public SqlWrapper()
{
}
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
public class SqlWrapper
{
public SqlWrapper()
{
}
}
}
Code:
public SqlWrapper(string connectionString)
{
}
Code:
SqlConnection Connection;
Code:
public SqlWrapper(string connectionString)
{
Connection = new SqlConnection(connectionString);
}
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
public class SqlWrapper
{
public SqlConnection Connection;
public SqlWrapper(string connectionString)
{
Connection = new SqlConnection(connectionString);
}
}
}
Make a new method called Command with the string parameter _command.
Code:
public void Command(string _command)
{
}
Code:
SqlCommand Command = new SqlCommand(_command, Connection);
Code:
try
{
}
catch
{
}
finally
{
}
You open the connection by doing this:
Code:
Connection.Open();
Code:
Command.ExecuteNonQuery();
Code:
public void Command(string _command)
{
SqlCommand Command = new SqlCommand(_command, Connection);
try
{
Connection.Open();
Command.ExecuteNonQuery();
}
catch
{
}
finally
{
}
}
Code:
catch (Exception e)
{
Console.WriteLine(e);
}
Code:
Connection.Close();
Code:
public void Command(string _command)
{
SqlCommand Command = new SqlCommand(_command, Connection);
try
{
Connection.Open();
Command.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
Connection.Close();
}
}
Create a new function for a string called ReadString.
Code:
public string Read(string Select, string From, uint UID)
{
}
Now put this 2 strings at the top of the function
Code:
string Value = "";
string Command = "SELECT " + Select + " FROM " + From + " WHERE UID = " + UID;
Now create a command using the previous connection again.
Code:
SqlCommand SQLCommand = new SqlCommand(Command, Connection);
Code:
SqlDataReader Reader;
Code:
try
{
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
Connection.Close();
}
Code:
Connection.Open();
Code:
Reader = SQLCommand.ExecuteReader();
Code:
while (Reader.Read())
{
}
Code:
Value = Reader[Select].ToString();
Code:
Reader.Close();
Code:
return Value;
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
public class SqlWrapper
{
public SqlConnection Connection;
public SqlWrapper(string connectionString)
{
Connection = new SqlConnection(connectionString);
}
public void Command(string _command)
{
SqlCommand Command = new SqlCommand(_command, Connection);
try
{
Connection.Open();
Command.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
Connection.Close();
}
}
public string Read(string Select, string From, uint UID)
{
string Value = "";
string Command = "SELECT " + Select + " FROM " + From + " WHERE UID = " + UID;
SqlCommand SQLCommand = new SqlCommand(Command, Connection);
SqlDataReader Reader;
try
{
Connection.Open();
Reader = SQLCommand.ExecuteReader();
while (Reader.Read())
{
Value = Reader[Select].ToString();
}
Reader.Close();
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
Connection.Close();
}
return Value;
}
}
}
Code:
Data Source=SERVERNAME;Initial Catalog=DATABASE;Integrated Security=True
DATABASE is the Database name.
There is other properties like password etc. you can be using them as well.
Might take a look here:

I think that's it.
How can we use it then?
Example:
Code:
SqlWrapper wrapper = new SqlWrapper("Data Source=SERVERNAME;Initial Catalog=DATABASE;Integrated Security=True");
Char.Name = wrapper.Read("Name", "Characters", Char.UID);






