I'm very new to C# so I'm using tutorials to get by.
I'm following a youtube tutorial on creating a login form. Linked here, at 10:00 mins into the video he starts inputting a connection string which was retrieved from the database earlier.
I followed the exact same steps inputting the following:
SqlConnection connnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="C: \Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Database1.mdf";Integrated Security=True");
However, I was surprised to see 26 errors all to do with that line. I suspected it was something to do with the string, as I read here that
You must also escape the back backslashes in your connection string \ becomes this \\
However, by using the @
symbol before the string it turns into a verbatim string
as I read here so that isn't the problem.
Now, I'm assuming that the issue lies with my app.config
as in other posts I've seen them add their connection string there, and then create a new connection string referencing that, but in the listed tutorial he doesn't do this, which leaves me confused.
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
Login button
private void buttonLogin_Click(object sender, EventArgs e)
{
SqlConnection connnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="C: \Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Database1.mdf";Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select count(*) from login where Username ='" + textBoxUsername.Text + "' and Password='" + textBoxPassword.Text + "'", connnection);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
LoginSuccess();
}
else
{
MessageBox.Show("Failed login.");
}
}
Error messages
Error CS1003 Syntax error, ',' expected Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1009 Unrecognized escape sequence Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1056 Unexpected character '\' Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1003 Syntax error, ',' expected Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1056 Unexpected character '\' Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1003 Syntax error, ',' expected Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1056 Unexpected character '\' Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1003 Syntax error, ',' expected Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1056 Unexpected character '\' Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1003 Syntax error, ',' expected Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1003 Syntax error, ',' expected Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1012 Too many characters in character literal Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1009 Unrecognized escape sequence Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1003 Syntax error, ',' expected Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1056 Unexpected character '\' Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1003 Syntax error, ',' expected Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1003 Syntax error, ',' expected Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1739 The best overload for 'SqlConnection' does not have a parameter named 'C' Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS0103 The name 'Users' does not exist in the current context Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS0103 The name 'Kevin' does not exist in the current context Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS1738 Named argument specifications must appear after all fixed arguments have been specified. Please use language version 7.2 or greater to allow non-trailing named arguments. Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS0103 The name 'source' does not exist in the current context Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS0103 The name 'repos' does not exist in the current context Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS0103 The name 'Kops' does not exist in the current context Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS0103 The name 'Toolbox' does not exist in the current context Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Error CS0103 The name 'Database1' does not exist in the current context Kops' Toolbox C:\Users\Kevin\source\repos\Kops' Toolbox\Kops' Toolbox\Form1.cs 62 Active
Database, named Database1
table is called UserData