Quick question on updating a local database object in C# with tables from a remote database

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hey guys I need a littl ebit of help with SQL Data Adapters.

1. I have pulled data from a ODBC Database via a dataAdapter and stored in a dataSet.


Question: How do I take that data (stored in a dataSet) and put it into a table I have stored in a local database of my C# program and then store those changes?
I have the database object as part of my C# program by adding it (Project -> Add New Item -> Service Based DB). Now Im trying to take my dataSet that I pulled from a database and put it into my local database object. The database is called "EVP.mdf",
it has EMPTY tables "Jan 17" and "Test" and I cannot for the life of me get it to update, save the changes and/or visibly reflect those changes.
Do I need to start a new connection between my program and my local database to update the tables? What can I do? Code posted
<br/>
<br/>
<br/>

<pre>using System;

namespace WindowsFormsApplication1
{
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;

public partial class Form1 : Form
{
System.Data.SqlClient.SqlConnection con;
DataSet ds1;
OdbcDataAdapter myDA;
SqlDataAdapter sqlAdpr;
EVPDataSet mine = new EVPDataSet();
public string command;

public Form1()
{
InitializeComponent();
}


private void Form1_Load(object sender, EventArgs e)
{

//dataGridView1.DataSource = bindingSource1;

}

private void button2_Click(object sender, EventArgs e)
{
using (OdbcConnection myConnect = new OdbcConnection())
{
myConnect.ConnectionString = "correct connection";
myConnect.Open();

String commandAsString = "select A.* into #temp from dbo.C_PRIZM_CD A ";
OdbcCommand myCommand = new OdbcCommand(commandAsString, myConnect);

myDA = new OdbcDataAdapter(commandAsString, myConnect);
ds1 = new DataSet();
myDA.Fill(ds1, "First");

bindingSource1.DataSource = ds1.Tables["First"];
dataGridView1.Invalidate();
myConnect.Close();

}
}[/code]

View the full article
 
Back
Top