23 years old, and I still didn’t know how to connect a microsoft sql with c#
That needed to change!
In the end, it’s almost exact the same as php/mysql or in netbeans…
You define a connection, you open it, and you’re ready to query
The hardest part was getting the data source (my local computer) right ^^
Plus, you can connect using your windows credentials (just run it), or define some specific user authentication.
In code, it looks like this:
private void button2_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("server=mendelportable\\sqlexpress;Trusted_Connection=yes;database=master;connection timeout=30");
myConnection.Open();
SqlCommand myCommand = new SqlCommand("select * from Table1", myConnection);
SqlDataReader dr = myCommand.ExecuteReader();
textBox1.Text = "";
while (dr.Read())
{
textBox1.Text=textBox1.Text+dr["messages"].ToString()+"\r\n";
}
}
And once you’re connected, you’re ready to query the hell out of that database
It’s absolutely nothing special, and it’s good to know!
Mission accomplished

two words: entity framework
things to do for tomorrow ^^
Sowiso ni op dees manier werken =p .
Entity frameworks zijn pakken beter én zijn tenminste OO.
En die sluiten u connectie ook af
“didn’t knew”
Ai, 23 jaar oud en nog steeds geen Engels kunnen, dat is pas erg :p
Misschien een beetje teveel verleden tijd ja ^^
Maar ik ben ervan overtuigd dat jij even goed fouten maakt
Ja eigenlijk wel, maar ik wou je gwn even confronteren hiermee
Voor de rest wel een heel interessant artikel, heb al een hoop kunnen leren van je blog !
Confrontaties zijn niet slecht
Zo leren we iedere dag iets eh :-p