K
Kevin.Anderson
Guest
Hello all,
I am trying to append text from textboxes in my winform to a DB that will be not be hosted on a server. I am having trouble doing this. Right now the DB is just in my solution file. Could someone look at my code and see if they can see whats wrong?
private void btnSubmit_Click(object sender, EventArgs e)
{
txtOrderdate.Text = DateTime.Now.ToString("MM/dd/yyyy hh:mm");
txtOrderNum.Text = "EZ" + txtFName.Text.Length + txtLName.Text.Length + DateTime.Now.ToString("hhmm");
string connectionString = "Server=C:\\Users\\me\\Dropbox\\work\\LazESolutions\\LazESolutions\\EZCustomers.sdf;Database=EZCustomers;Trusted_Connection=True;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("INSERT INTO Customers (FirstName, LastName, Address, HomePhone, MobilePhone, Comments, City, State, Zip, OrderDate, Email, GUID) VALUES (@FirstName, @LastName, @Address, @HomePhone, @MobilePhone, @Comments, @City, @State, @Zip, @OrderDate, @Email, @OrderNum)");
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@FirstName", txtFName.Text);
cmd.Parameters.AddWithValue("@LastName", txtLName.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@HomePhone", txtHPhone.Text);
cmd.Parameters.AddWithValue("@MobilePhone", txtMPhone);
cmd.Parameters.AddWithValue("@Comments", txtComments.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", txtState.Text);
cmd.Parameters.AddWithValue("@Zip", txtZip.Text);
cmd.Parameters.AddWithValue("@OrderDate", txtOrderdate);
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
cmd.Parameters.AddWithValue("@OrderNum", txtOrderNum.Text);
connection.Open();
cmd.ExecuteNonQuery();
}
Continue reading...
I am trying to append text from textboxes in my winform to a DB that will be not be hosted on a server. I am having trouble doing this. Right now the DB is just in my solution file. Could someone look at my code and see if they can see whats wrong?
private void btnSubmit_Click(object sender, EventArgs e)
{
txtOrderdate.Text = DateTime.Now.ToString("MM/dd/yyyy hh:mm");
txtOrderNum.Text = "EZ" + txtFName.Text.Length + txtLName.Text.Length + DateTime.Now.ToString("hhmm");
string connectionString = "Server=C:\\Users\\me\\Dropbox\\work\\LazESolutions\\LazESolutions\\EZCustomers.sdf;Database=EZCustomers;Trusted_Connection=True;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("INSERT INTO Customers (FirstName, LastName, Address, HomePhone, MobilePhone, Comments, City, State, Zip, OrderDate, Email, GUID) VALUES (@FirstName, @LastName, @Address, @HomePhone, @MobilePhone, @Comments, @City, @State, @Zip, @OrderDate, @Email, @OrderNum)");
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@FirstName", txtFName.Text);
cmd.Parameters.AddWithValue("@LastName", txtLName.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@HomePhone", txtHPhone.Text);
cmd.Parameters.AddWithValue("@MobilePhone", txtMPhone);
cmd.Parameters.AddWithValue("@Comments", txtComments.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", txtState.Text);
cmd.Parameters.AddWithValue("@Zip", txtZip.Text);
cmd.Parameters.AddWithValue("@OrderDate", txtOrderdate);
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
cmd.Parameters.AddWithValue("@OrderNum", txtOrderNum.Text);
connection.Open();
cmd.ExecuteNonQuery();
}
Continue reading...