Return newly inserted row without having to Submit to database - sql

I need to find a way to get the newly insert row, without previously having to save to the database.
Is there a way? Or I need to keep the whole collection of row in a separated array?
Is this example I adding a row to the table tblConfig, but when I look back in the table the new row is not there.
tblConfig Config = new tblConfig { ID = Guid.NewGuid(), Code ="new config code" };
CTX.tblConfig.InsertOnSubmit(Config);
var Data = from dd in CTX.tblConfig select dd;
this.dataGridView1.DataSource = Data;

After some research , I'll do the work by attaching my LINQ query to a BindingSource object, witch will help me handle with insertion update and so.
Thanks for everyone, for your help :)
Hugo

Could you add that manually like this?
this.dataGridView1.DataSource = CTX.tblConfig.Execute(MergeOption.AppendOnly);

Related

How to loop google-Apps script?

I would like to gather subscribers for the channel id of youtube with an app script on Google Spreadsheets. But it only worked with one id.
I'd like to use a repeat statement, but I can't because I'm not good enough. I'd appreciate it if you could help me.
function getChannelInfo() {
var ss = SpreadsheetApp.getActiveSheet();
var channel = ss.getRange("B2").getValue();
var data = YouTube.Channels.list('statistics', {id: channel});
var item = data.items[0];
var info = [item.statistics.subscriberCount];
ss.getRange("C2").setValues([info]);
}
I want to gather subscribers for all video IDs in column B, but only one comes out. Help me.
https://docs.google.com/spreadsheets/d/1Ks_tE9uDdOcTKML8jf_40lJpcImMoh-JYivpV38zpCk/edit?usp=sharing
No problem
In this statement var channel = ss.getRange("B2").getValue();, you are calling just one value. Instead you should go with an array of values. Like ss.getrange(row, colum, number of rows).getdisplayvalues();
use FOR LOOP to run for each value in the above array and set values in the Spreadsheet in the corressponding cells.
Let me know if you need help :)

How to add an array of datarows into an exisitng table inside my database

I'm a newbie so don't laugh :#
I'm working with 2002-2003 Microsoft access database.
Now, I want to add an array of DataRow into an existing table that I've in my database. Is there a way to do that? because right now I'm just adding the rows with a foreach loop
thank you
I think that the foreach-loop actually is the best way to do it.
foreach(DataRow row in yourRowArray)
{
dataTable.Add(row);
}
If you are using .Net Framework 3.5+ you can also use the DataRows CopyToDataTable() Method.
But you have to watch out because the Data in the DataTable is overwritten in this case.
DataTable table = yourDataTable;
DataRow[] yourRowArray = ...;
if(yourRowArray.Length > 0)
{
table = yourRowArray.CopyToDataTable();
}
I would recommend using the foreach-loop.
What you describe as array must be a saved file type i.e. excel or csv. Be sure it is a clean grid of data without extraneous non aligned rows.
Then you can link to that file with Access as a table. This is a manual step using the Access interface - in the ribbon it is the External area. This link remains good - allowing you to replace the excel/csv with a new one as long as the location path and structure of the file do not change.
Then you create an Append query to write all the records from this table into the table in your Access database.
www.CahabaData.com

oxid import old data SQL

I have an old oxid-version. I exported my old seo-data from the table "oxseo" to get the keywords and description for each article. Now i want to import these fields in my new version of the shop. My articles are already there, but not the seodata.
My first idea was to collect all the data i need from a csv-export of my old data.
For example, my output array could look something like:
$article = array();
$keywords = array();
$desc = array();
foreach($line as $l) {
$keywords[$i] = current_keyword
$desc[$i] = current_description
$oxid[$i] = current_oxid
}
So lets just assume I already have my filled array.
If i check the oxid's, they are still the same. So, from my exported CSV, picking a random OXID, looking for it in my new DB shows me the correct article.
Now my first thought was, to look in oxobject2seodata. I know that the data for the articles are stored in there, but i can't find a way to connect those, since the "oxid" from the old version is not the same as the objectId in the new version. In oxarticles, however, there is no "objectId".
Thank you in advance for any hints and tips
The field OXID in oxarticles table should match the field OXOBJECTID in oxobject2seodata table.
SELECT oa.OXID, o2s.* from oxobject2seodata o2s, oxarticles oa WHERE o2s.OXOBJECTID = oa.OXID AND oa.OXID = '[OXID-of-article]';
-- or
SELECT o2s.* from oxobject2seodata o2s WHERE o2s.OXOBJECTID = '[OXID-of-article]';

Locate database entry based on ID from another database entry in rails

I've been digging around a little trying to figure out how I should locate the "tweet_id" in my #savedtweets table and then locate that same "tweet_id" in my #newtweets table from a controller, so far I'ved tried something like this;
CONTROLLER
#stweet = Savedtweet.find(params[:id])
#newtweet = Newtweet.where(:tweet_id => #stweet.tweet_id)
#newtweet.status = 'new'
#newtweet.save
Basically I need to change the string "saved" in my Newtweets table to "new" based on the current Savedtweet ID. I just can't figure it out. If I do the following in console;
#stweet = Savedtweet.first
#newtweet = Newtweet.where(:tweet_id => #stweet.tweet_id)
It finds the right one. I've got to be close just not there yet. :)
You could do:
Newtweet.find_by_tweet_id(#stweet.tweet_id).update_attribute(:status, 'new')
The reason your code isn't working is because Newtweet.where() returns an array of objects. It should be Newtweet.where().first, though Newtweet.find_by_tweet_id is the preferred method.

Add data from one table to another in ruby on rails

In my current project, I have to get some data in a column of one table and put them to the 2nd table. The first table data have been saved as hash as follows:
---
- werweqr
- test
- B1
- B2
- B3
- xvxczv
I write the following code in the migration file to add the data from the first table to the 2nd table. But the data are not sending from the first to second.
#scenario_response = ScenarioResponse.where("selected_barriers != ?", "");
#scenario_response.each do |p|
p.selected_barriers.each do |barrier|
Settings.test = barrier
# SelectedBarriers.create(:scenario_response_id => p.id, :barrier => barrier)
end
end
Can anyone please let me know if there's something wrong in my code.
If so how to fix it?
Thanks a lot
I don't think you need to call "each" on p.selected_barriers.Try removing the each and doing this:
Settings.test=p.selected_barriers.
I'm new to RoR too..According to me,the scenario_response is a collection that returns all instances that have the selected_barriers as "". Since you are doing an each on the collection, you will just have one selected_barriers item for each of them.
Please try this and let me know if I'm wrong.
Also you are not doing update_attributes.
Try doing Settings.update_attributes(params[:test]) after Settings.test = barrier .