First I would like to say that I thought that my problem was easily solved but after a lot of trying and searching I am not making any progress (I am also a complete beginner when it comes to databases).
I made a database with Microsoft SQL Server and called it UltimatePokerDB. I added a table MyTable I added two columns sevenKeys and sevenValues
this is visible in Visual Studio Image of my Server Explorer in visual studio
and makes this SQL code
CREATE TABLE MyTable
(
[sevenKeys] BINARY(56) NOT NULL PRIMARY KEY,
[SevenValues] BINARY(48) NOT NULL
)
I have the following code written in my Main method
string provider = "System.Data.SqlClient";
string connectionstring = "Server=localhost;Database=master;Trusted_Connection=True;";
byte[] one = new byte[7];
byte[] two = new byte[6];
DbProviderFactory factory = DbProviderFactories.GetFactory(provider);
using (SqlConnection cnn = new SqlConnection(connectionstring))
{
string sql = "insert into MyTable (sevenKeys, sevenValues) values(@first,@last)";
cnn.Open();
using (SqlCommand cmd = new SqlCommand(sql, cnn))
{
cmd.Parameters.AddWithValue("@first", one);
cmd.Parameters.AddWithValue("@last", two);
cmd.ExecuteNonQuery();
Console.WriteLine("row inserted");
}
}
I get an error at cmd.ExecuteNonQuery() and it says: System.Data.SqlClient.SqlException: 'Invalid object name 'MyTable'.'
Basically Im giving it the wrong name but I have no clue what it wants me to do...