dataset to sql express db (from text file)

  • 10 years ago

    I have a dataset that that I'm trying to import into an embedded SQL 2005 Express database. I have seen the dataset & so the data is getting there. I wrote some code to insert test data into the Express db so I know that is working. I just can't get the dataset to insert into the database. The fields in this particular table are stable_id (primary key), location, movein _date, moveout_date. Here is the code that I think is causing the problem - let me know if seeing any more of the code would help. I am a newbie to programming...Thanks for any ideas! Casey

    DataSet ds2 = new DataSet();

    int intLengthOfFileName = txtStable.Text.Trim().Length;

    int intLastIndex = txtStable.Text.Trim().LastIndexOf("\\");

    strFile = txtStable.Text.Trim().Substring(intLastIndex, intLengthOfFileName - intLastIndex);

    strFile = strFile.Remove(0, 1);

    ds2 =

    this.ConnectText(strFile); //this fills the dataset

    string strConnString = "Data Source=.\\SQLExpress;AttachDbFilename=C:\\Documents and Settings\\Casey\\My Documents\\Visual Studio 2005\\Projects\\Rep\\Reporter\\Rep.mdf;Integrated Security=true; User Instance=true;";

    SqlConnection con1 = new SqlConnection(strConnString);

    SqlDataAdapter sdaLoad = new SqlDataAdapter("SELECT * FROM stable", con1);

    sdaLoad.MissingSchemaAction =

    MissingSchemaAction.AddWithKey;

    SqlCommandBuilder scbLoad = new SqlCommandBuilder(sdaLoad);

    con1.Open();

    sdaLoad.Update(ds2,

    "stable");

    con1.Close();

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debuggers don't remove bugs. They only show them in slow motion.”