Copying data to a text box associated with an SQL Dataset RRS feed

  • Question

  • Hello, I have just recently started playing around with VC#EE and have a question concerning what I have listed in the subject. I am new to programming in the Windows environment so please bear with me if I am rough with the terminology.

    Essentially, I am trying to create a database using the SQL Serve Express and I want to import the data that is to be in the data base from a text file. Using the free e-book "...Build a program now!" I have created the data base using SQL SE. I have been able to get up to the point to where I place a text box object for each of fields in the dataset on my form and when I run the program I can enter data into each field and save it to the data base using the mouse and keyboard. Where I am having trouble is understanding how to get data into those text boxes with my program other than using the keyboard. I have searched and haven't found another thread similiar so if possible, please also send me the link. Here is a listing of the MSDN topics I have researched:

    How to: Create TableAdapter Queries

    How to: Save Data from an Object to a Database

    How to: Fill a Dataset with Data

    TableAdapter Overview

    How to: Update Data using a TableAdapter

    Walkthrough: Saving Data to a Database (Single Table)

    Thank you for your time and consideration.


    Monday, November 20, 2006 5:08 AM


  • I think that I have figured out a solution. Here is the code that loads the data from the text file to the database. I end up running into some null character issues with my primary key field, but at least the data is getting saved to the database.


    private void button1_Click(object sender, EventArgs e)


    if (openFileDialog1.ShowDialog() == DialogResult.OK)


    System.IO.StreamReader sr = new


    String line;

    int i = 1;

    while ((line = sr.ReadLine()) != null)


    char[] delimiterChars = { '\t' };

    string[] data = line.Split(delimiterChars);

    textBox1.Text = i.ToString();

    textBox2.Text = data[0];

    textBox3.Text = data[1];

    textBox4.Text = data[2];

    partIDTextBox.Text = textBox1.Text;

    partNumberTextBox.Text = textBox2.Text;

    descriptionTextBox.Text = textBox3.Text;

    costTextBox.Text = textBox4.Text;





    if (line != null)






    partIDTextBox.Text = i.ToString();







    Monday, November 20, 2006 9:33 PM