Suppose, We have two databases , db_1 and db_2.
There are a table named 'T1' in db_1, now,I need a package in SSIS which will ask for names sql objects.If I choose 'T1',the data will be transfered to db_2.
I dont know if it is possible.
Generally SSIS is not meant to be used in an Interactive mode. Any user input is either introduced as a config setting or environment variable or as values in some other table.
Alternately, you can also prompt for and capture input values outside of the SSIS Package and then execute the SSIS Package, in C# or ASP.Net or any other interactive platform.
That said, if you must prompt for input and use it, the way to do it is by instantiating and displaying a Form in a Script Component.
Create a variable at the appropriate scope called tableName in the package. Then use the code below (modify it as needed) to set the tableName variable's value to whatever the user enters. Finally, use the same tableName variable in your control flow to copy the data from.
System.Windows.Forms.Form frm = new Form();
TextBox = new TextBox();
Button submitButton = new Button();
public void Main()
{
submitButton.Text = "Enter source table name";
submitButton.Width = 300;
submitButton.Height = 80;
submitButton.Click += new EventHandler(submitButton_Click);
tableNameTextBox.Name = "Input";
frm.Controls.Add(tableNameTextBox);
frm.Controls.Add(submitButton);
frm.ShowDialog();
MessageBox.Show(Dts.Variables["tableName"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;
}
void submitButton_Click(object sender, EventArgs e)
{
Dts.Variables["tableName"].Value = tableNameTextBox.Text;
frm.Close();
}
Ref: https://stackoverflow.com/a/4121557/325521
Related
I apologize if has been asked, and answered somewhere else, but I have been searching like crazy and can't find what I'm looking for.
OleDbConnection^ conn = gcnew OleDbConnection ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Milestone3testdatabase.accdb; Persist Security Info=True");
OleDbCommand^ com = gcnew OleDbCommand();
com->Connection = conn;
com->CommandText = "SELECT *FROM tblcity;";
System::Data::DataSet^ ds = gcnew System::Data::DataSet();
OleDbDataAdapter^ adapt = gcnew OleDbDataAdapter();
adapt->SelectCommand = com;
adapt->Fill(ds,"why");
dataGridView1->DataSource = ds->Tables["why"];
I am trying to figure out how to actually use the data I obtain from the database. I was shown how to put it into a gridview, BUT I don't want a gridview. I want be able to take 1 cell of the table and display it as text.
How do I convert the table into usable data for a C++ forms application?
Either modify your SELECT so that it returns only a single value by using SqlCommand.ExecuteScalar Method or extract the value from your table with the DataTable.Select Method and DataTable.Rows Property
myDataTable->Rows[rowNumber][columnNumber]
I have a database and a winform application in visaul c++. The db has two columns Date and Temp. These values are automatically inserted in the db by a different c++ program which is scheduled to run every 2-3 second. In the form there is a button "Show Plot" which on clicking would show the Date vs Temp graph. I am able to do this. However what i want is that this graph keeps updating based on the new values in the database...something like a heart beat monitor or to that effect. How can i achieve this. Please advice how can i do this using winform project in visual c++ and THREAD programming
Reards
PS: As i am using Winform application in visual c++ a lot of code is generated for th picture elemnets. Some part which may help are:
private: System::Void temperature_btn_Click(System::Object^ sender, System::EventArgs^ e) {
String^ constring = L"datasource=localhost;port=3306;username=root;password=root;";
MySqlConnection^ conDataBase = gcnew MySqlConnection(constring);
MySqlCommand^ cmdDataBase = gcnew MySqlCommand("select * from `data`.`test`;",conDataBase);
MySqlDataReader^ myReader;
try{
conDataBase->Open();
myReader = cmdDataBase->ExecuteReader();
// MessageBox::Show("Data Inserted");
while(myReader->Read()){
String^ v_datetime;
String^ v_pressure;
v_datetime = myReader->GetString("datetime");
v_pressure = myReader->GetInt32("temp").ToString();
String^ status;
if (myReader->GetInt32("temp") > 1000 && myReader->GetInt32("temp") < 50 )
{
status = " Abnormal ";
this->chart2->Series["Temperature"]->Color = System::Drawing::Color::Red;
}
else{
status = " Normal";
}
this->label3->Text = status;
this->chart2->Series["Temperature"]->Points->AddXY(v_datetime,myReader->GetInt32("temp"));
// comboBox1->Items->Add(vName);
}
}catch(Exception^ex){
MessageBox::Show(ex->Message);
}
}
What needs to be done to make this dynamic...i.e, the chart keeps picking values from the database at regural intervals...say every 3-5 seconds (the db is being updated by another completely unrelated process every 2-3 second)
PS EDIT 2: sorry...i should have made it clear... how to do this by threads...i apologise once again for not being clear
Add a Timer to your Windows Form (from the Toolbox) and register an EventHandler for the Tick event. Also set the "Intervall" to a value you want. Then either set the property "Enabled" to "true" or start it manually in the "Form_Loaded" EventHandler.
I created a Windows Form, with a ComboBox, and a Local Database in Visual Studio 2010. The database has a table with a column whose rows I want to list in the combo box. How can I achieve this?
I tried adding a data source with the column I am interested in through the IDE, but it did not work.
I created a Windows Forms Application with a Windows Form containing a ComboBox.
I created a Local Database containing a Table with a single column and three test rows.
I added a data source containing the column I am interested in.
Finally, I bound the combo box to the data source, but the result is strange.
This is the raw code to accomplish what you are asking:
string strCmd = "";
string strConn = "";
SqlConnection sqlConn = new SqlConnection();
SqlCommand sqlCmd = new SqlCommand(strCmd, sqlConn);
SqlDataReader sqlRdr = new SqlDataReader();
sqlConn.Open();
if (comboBox1.Items.Count > 0)
comboBox1.Items.Clear();
sqlRdr = sqlCmd.ExecuteReader();
while (sqlRdr.Read())
comboBox1.Items.Add(sqlRdr[0].ToString());
sqlRdr.Close();
sqlConn.Close();
There are a few things you will need to wire-up first though. The first one is this:
string strCmd = ""; // Insert your SQL statement here.
Second:
string strConn = ""; // Your db connection string goes here.
Thirdly:
if (comboBox1.Items.Count > 0) // You don't have to use this. It just checks to see
comboBox1.Items.Clear(); // if there is anything in the combobox and clears it.
Lastly, since you are making something that handles interactions between your form and a database, I strongly suggest that you use SqlParameters to prevent SQL Injection attacks.
I'm changing my WPF application to use the Entity Framework instead of calling sql db directly.
On this one window I have a listview containing a gridview and I'm databinding it by using the following method which calls a stored procedure to get the data.
Now I already have my model generated from my existing sql database and included the stored proc...
How would I go about changing this method to read the data from the entity model instead of directly from sql?
public static void BindData(DataGrid grid)
{
SqlConnection loginCon = new SqlConnection();
loginCon.ConnectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlDataAdapter adapter = new SqlDataAdapter("sp_SELECT_CONSHEAD", loginCon))
{
DataSet data = new DataSet();
adapter.Fill(data);
grid.ItemsSource = data.Tables[0].DefaultView;
}
}
You can use Function Import to get the stored procedure mapped to entity in EntityFramework. Then you can directly call the function in your code with single line of code.
grid.ItemsSource = dbContext.GetSP_Select_Conshead();
I am a beginner to programming and I am trying to make a program that tracks my jogging data in WPF. I set up a listbox that has databinding with my compact sql database where my info gets logged to. While I am in visual studio it works as it should, but when I publish the program, the listbox will no longer display the proper info from the database. It starts fresh all over again each time I start a new session of the program. I know that the info is in the database because I have charts that will properly show all the latest logged data. The listbox, however, will only show data logged during that current session. When I close down the program and reopen, the data from my previous session is not displayed in the listbox anymore.
My code looks like this:
runDataDataSet1 ds;
runDataDataSet1TableAdapters.runDataTableTableAdapter dt;
weightDataSet wds;
weightDataSetTableAdapters.weightTableTableAdapter wdt;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ds = ((runDataDataSet1)(this.FindResource("runDataDataSet1")));
dt = new runDataDataSet1TableAdapters.runDataTableTableAdapter();
dt.Fill(ds.runDataTable);
CollectionViewSource cvs = ((CollectionViewSource)(this.FindResource("runDataTableViewSource")));
cvs.View.MoveCurrentToFirst();
wds = ((weightDataSet)(this.FindResource("weightDataSet")));
wdt = new weightDataSetTableAdapters.weightTableTableAdapter();
wdt.Fill(wds.weightTable);
CollectionViewSource wcvs = ((CollectionViewSource)(this.FindResource("weightTableViewSource")));
wcvs.View.MoveCurrentToFirst();
To submit the data I have this code for when the submit button is pushed:
double pace = runData.runPace(runData.milesRun, runData.timeRun);
double pace2 = Math.Round(pace, 1);
double milesDuration = Math.Round((runData.mileDuration(runData.milesRun, runData.timeRun)), 1);
paceTextBox.Text = ((milesDuration) + " min mile");
//UPDATE DATABASE
string myConnectionString = #"Data Source=C:\Users\zfam\My Projects\programming\visual studio\XTrakker\XTrakker\runData.sdf";
string mySelectQuery = "SELECT [int], [runDate], [runDist], [runTime], [runPace] FROM [runDataTable] order by [int] desc";
DataRow dr = ds.Tables["runDataTable"].NewRow();
SqlCeDataAdapter adapter = new SqlCeDataAdapter(mySelectQuery, myConnectionString);
dr["runDate"] = date;
dr["runDist"] = distData;
dr["runTime"] = timeData;
dr["runPace"] = milesDuration;
ds.Tables["runDataTable"].Rows.Add(dr);
SqlCeCommandBuilder projectBuilder = new SqlCeCommandBuilder(adapter);
DataSet newSet = ds.GetChanges(DataRowState.Added);
adapter.Update(newSet, "runDataTable");
adapter.Dispose();
Again, while I am in visual studio and I run the program, this all works as it should. Once I publish, the listbox will only show the data from the current session, even the the actual database file is being updated. Perhaps I am doing this all wrong? Any thoughts?
Hard to say, but I am a bit confused about this line:
string myConnectionString = #"Data Source=C:\Users\zfam\My Projects\programming\visual studio\XTrakker\XTrakker\runData.sdf";
Look like you hardcode your datasource provider. Are you sure you use the same datasource in visual studio, and when you publish your app?
Maybe the datasource is re-created at each execution, which could explain why you have always new data.