Hi, I'm currently learning C# and I'm currently learning how to do C# and Database's. Does anyone know why it isn't adding the data in the text boxes to the db.
Cheers Sam
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.SqlClient;
namespace SQL_ATTEMPT_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection cs = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database1.mdf;Integrated Security=True;User Instance=True");
SqlDataAdapter da = new SqlDataAdapter();
da.InsertCommand = new SqlCommand("INSERT INTO tblUsers VALUES(@USERNAME, @PASSWORD)", cs);
da.InsertCommand.Parameters.Add("@USERNAME", SqlDbType.VarChar).Value = textBox1.Text;
da.InsertCommand.Parameters.Add("@PASSWORD", SqlDbType.VarChar).Value = textBox2.Text;
MessageBox.Show(textBox1.Text);
cs.Open();
da.InsertCommand.ExecuteNonQuery();
cs.Close();
}
}
}