I am new to the forums but I was refered here to get some help. My problem is that i have a list text box and a database and I know how to insert my data into it. Which works perfectly fine, But when I have no idea where to start to get the list box to show the data that was inputed.
Here is my Insert Code
private void button1_Click_1(object sender, EventArgs e)
{
Form1.lb.Items.Add(textBox1.Text + "" + textBox2.Text);
string connectionstring = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
SqlConnection connection = new SqlConnection(connectionstring);
string First = textBox1.Text;
string Last = textBox2.Text;
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = ("INSERT INTO [User] ([First Name],[Last Name]) VALUES (@First, @Last)");
command.Parameters.AddWithValue("@First", First);
command.Parameters.AddWithValue("@Last", Last);
connection.Open();
command.ExecuteNonQuery();
}
This works fine.
So basically i have that you type in the text box and it inputs it into the database. But then i need, in Form 1 to automatically pull that information and make it an Item in the list. I have spent 2 hours already and have looked at tutorial around the web heck i even searched your site. Im new to Sql but not c#

New Topic/Question
Reply




MultiQuote




|