Click here to Skip to main content
15,888,984 members
Home / Discussions / C#
   

C#

 
GeneralRe: database updation Pin
raju_net181822-Jan-07 21:46
raju_net181822-Jan-07 21:46 
Questiongetting a dataset of affected records,using an ExecuteNONQuery OleDbCommand Pin
dsovino22-Jan-07 15:23
dsovino22-Jan-07 15:23 
AnswerRe: getting a dataset of affected records,using an ExecuteNONQuery OleDbCommand Pin
Guffa22-Jan-07 19:30
Guffa22-Jan-07 19:30 
GeneralRe: getting a dataset of affected records,using an ExecuteNONQuery OleDbCommand Pin
aSarafian23-Jan-07 1:06
aSarafian23-Jan-07 1:06 
AnswerRe: getting a dataset of affected records,using an ExecuteNONQuery OleDbCommand Pin
Guffa23-Jan-07 5:36
Guffa23-Jan-07 5:36 
GeneralRe: getting a dataset of affected records,using an ExecuteNONQuery OleDbCommand Pin
aSarafian23-Jan-07 7:51
aSarafian23-Jan-07 7:51 
GeneralRe: getting a dataset of affected records,using an ExecuteNONQuery OleDbCommand Pin
Guffa23-Jan-07 12:23
Guffa23-Jan-07 12:23 
QuestionRe: getting a dataset of affected records,using an ExecuteNONQuery OleDbCommand Pin
dsovino23-Jan-07 4:14
dsovino23-Jan-07 4:14 
Ok, but how do I get this done?

I had lots of troubles working with access database and the dataset wizard to store querys (http://forums.microsoft.com/MSDN/showpost.aspx?postid=1121807&siteid=1), so I opted to run my queries with code.

I used one method with the Insert command, and if the result set is higher than 0, I call another method with a Scalar Command, to search for the ID. Then, with the retrieved ID, i call the third method to Insert the record ID on the second table....
Sleepy | :zzz:

The code described below worked well, everyonce in a while (no clue yet why sometimes i'm able to get the ID and sometimes I get 0, probably something going on with the query). So that's why I want a safer way to get this done.

I searched a little bit for "select @@identity" (http://support.microsoft.com/kb/816112), and I found out that it behaves as a Scalar command as well. So in theory, i should just change my query string to get it done.

It doesnt work at all. Does the "select @@identity" statement work only when you handle it on a OleDbDataAdapter.RowUpdated Event?


Thanks for the help!


<br />
<br />
string file = "......";<br />
<br />
private void InsertAudio()<br />
<pre>
<small>
{  // creation of queries, source, connections, etc....  

   OleDbCommand cmd = new OleDbCommand(sql, conexion);
   int resultSet;

            try
            {
                conexion.Open();
                resultSet = cmd.ExecuteNonQuery();

                if (resultSet > 0) SearchIDofCreatedRow();
                    
            }
            catch (OleDbException ode)
            {
                MessageBox.Show(ode.ToString(), "Error de Conexion con base de datos");
            }
            finally  {conexion.Close();}
}
</small>
</pre><br />
<br />
<br />
private void SearchIDofCreatedRow()<br />
<pre>
<small>
{
// creation of queries, source, connections, etc....  

   OleDbCommand cmd = new OleDbCommand("SELECT ID FROM audios WHERE file='" + file + "'", conexion);

            try
            {
                conexion.Open();
                int ID = Convert.ToInt32(cmd.ExecuteScalar());
                AddCategoryList(ID);
            }

//catch/finally.....
}
</small>
</pre><br />
<br />
private void AddCategoryList(int ID)<br />
<pre>
<small>
{
//
//Insert into the second table with the retrieved data....
//
}
</small>
</pre> <br />
<br />
daniel sovino

AnswerRe: getting a dataset of affected records,using an ExecuteNONQuery OleDbCommand Pin
Guffa23-Jan-07 5:42
Guffa23-Jan-07 5:42 
QuestionPass parameter in MouseEventHandler Pin
cocoonwls22-Jan-07 15:16
cocoonwls22-Jan-07 15:16 
AnswerRe: Pass parameter in MouseEventHandler Pin
Luc Pattyn22-Jan-07 15:32
sitebuilderLuc Pattyn22-Jan-07 15:32 
GeneralRe: Pass parameter in MouseEventHandler Pin
cocoonwls22-Jan-07 16:00
cocoonwls22-Jan-07 16:00 
QuestionDataGridView Redraw Pin
jzb22-Jan-07 14:33
jzb22-Jan-07 14:33 
AnswerRe: DataGridView Redraw Pin
jzb23-Jan-07 0:27
jzb23-Jan-07 0:27 
Questionperform multiple task Pin
Eddymvp22-Jan-07 12:59
Eddymvp22-Jan-07 12:59 
AnswerRe: perform multiple task Pin
Marc Clifton22-Jan-07 13:51
mvaMarc Clifton22-Jan-07 13:51 
QuestionHashtable Object access Pin
gigo2k622-Jan-07 12:15
gigo2k622-Jan-07 12:15 
AnswerRe: Hashtable Object access Pin
Marc Clifton22-Jan-07 12:33
mvaMarc Clifton22-Jan-07 12:33 
GeneralRe: Hashtable Object access Pin
gigo2k622-Jan-07 12:36
gigo2k622-Jan-07 12:36 
GeneralRe: Hashtable Object access Pin
Christian Graus22-Jan-07 12:41
protectorChristian Graus22-Jan-07 12:41 
GeneralOT Pin
Marc Clifton22-Jan-07 12:57
mvaMarc Clifton22-Jan-07 12:57 
GeneralRe: OT Pin
Christian Graus22-Jan-07 17:27
protectorChristian Graus22-Jan-07 17:27 
GeneralRe: OT Pin
Marc Clifton23-Jan-07 1:36
mvaMarc Clifton23-Jan-07 1:36 
AnswerRe: Hashtable Object access Pin
Christian Graus22-Jan-07 12:37
protectorChristian Graus22-Jan-07 12:37 
AnswerRe: Hashtable Object access Pin
Guffa22-Jan-07 12:40
Guffa22-Jan-07 12:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.