Elite Ninja
10-27-2011, 11:23 AM
In my programming class I am trying to make an SQL Database in Microsoft Visual C# 2010 Express using a windows form that would allow you to input data (such as a username and password) into the database.
This is the first time I have messed with SQL and I have no idea what I am doing >.> I am not sure what you would need to know to help me but I will provide the code I have and a SS of the table I have for the database.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace SQL_Database_Project
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void RegisterButton_Click(object sender, EventArgs e)
{
string connection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\UserDatabase.mdf;Integrated Security=True;User Instance=True";
SqlConnection cn = new SqlConnection(connection);
string username = UsernameTextBox.Text;
string password = PasswordTextBox.Text;
string sqlquery = "INSTERT INTO [UserTable] (Username, Password) VALUES ('" + UsernameTextBox.Text + "," + "'" + PasswordTextBox.Text + "')";
SqlCommand command = new SqlCommand(sqlquery, cn);
try
{
cn.Open();
}
catch (Exception)
{
MessageBox.Show("Did not connect");
}
command.Parameters.AddWithValue("Username", username);
command.Parameters.AddWithValue("Password", password);
command.Parameters.Clear();
}
private void Form1_Load(object sender, EventArgs e)
{
string connection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\UserDatabase.mdf;Integrated Security=True;User Instance=True";
SqlConnection cn = new SqlConnection(connection);
try
{
cn.Open();
}
catch (Exception)
{
MessageBox.Show("Did not connect");
}
}
}
}
http://i1232.photobucket.com/albums/ff375/ElitexNinja/SQLDatabaseForm.jpg
http://i1232.photobucket.com/albums/ff375/ElitexNinja/SQLDatabaseTable.jpg
This is the first time I have messed with SQL and I have no idea what I am doing >.> I am not sure what you would need to know to help me but I will provide the code I have and a SS of the table I have for the database.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace SQL_Database_Project
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void RegisterButton_Click(object sender, EventArgs e)
{
string connection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\UserDatabase.mdf;Integrated Security=True;User Instance=True";
SqlConnection cn = new SqlConnection(connection);
string username = UsernameTextBox.Text;
string password = PasswordTextBox.Text;
string sqlquery = "INSTERT INTO [UserTable] (Username, Password) VALUES ('" + UsernameTextBox.Text + "," + "'" + PasswordTextBox.Text + "')";
SqlCommand command = new SqlCommand(sqlquery, cn);
try
{
cn.Open();
}
catch (Exception)
{
MessageBox.Show("Did not connect");
}
command.Parameters.AddWithValue("Username", username);
command.Parameters.AddWithValue("Password", password);
command.Parameters.Clear();
}
private void Form1_Load(object sender, EventArgs e)
{
string connection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\UserDatabase.mdf;Integrated Security=True;User Instance=True";
SqlConnection cn = new SqlConnection(connection);
try
{
cn.Open();
}
catch (Exception)
{
MessageBox.Show("Did not connect");
}
}
}
}
http://i1232.photobucket.com/albums/ff375/ElitexNinja/SQLDatabaseForm.jpg
http://i1232.photobucket.com/albums/ff375/ElitexNinja/SQLDatabaseTable.jpg