Inserted rows not "sticking"

  • Thread starter news.public.microsoft.com
  • Start date
N

news.public.microsoft.com

Hello all!
I'm having an issue with an asp.net app (vb.net code) and ado.net. I've
written up the following piece of code everything I've read says it should
work without an issue. Debugging I see that after the last line of code
executes my myDataTable object has one additional row in it as it should.
Using the command window I can check the data contained in the last row and
is indeed the data from the rows trying to be inserted into the table. The
issue is that the data never actually makes it into the database. No errors
are reported and everything executes fine. Am I missing something else that
needs to be committed or sync'd? Thanks for any information you guys/gals
might have to offer.

'--------------- Code starts -------------------'
Dim connectionString As String
connectionString = "Server=localhost; uid=sa; pwd=sapassword; database=test"

Dim commandString As String
commandString = "Select * from " & Application("UnreleasedTimeTable")

Dim myDataAdapter As New System.Data.SqlClient.SqlDataAdapter(commandString,
connectionString)
Dim myDataSet As New DataSet

myDataAdapter.Fill(myDataSet)

Dim myDataTable As DataTable = myDataSet.Tables(0)

Dim newRow As DataRow = myDataTable.NewRow

newRow("UserID") = Session("UserObj").TraverseUserID
newRow("Code") = cboType.SelectedValue.ToString
newRow("TDate") = cboDate.SelectedValue.ToString
myDataTable.Rows.Add(newRow)
'--------------- Code ends -------------------'

Regards,
-Tony
 
N

Norman Yuan

Obviously your reading stops at how to get data from databse into
DataSet/DataTable and add/remove data to /from Dataset/Datatable. You need
to read a bit more to know how to update back to database through
SqlDataAdapter/SqlCommand. DataSet/DataTable is disconnected from database.
No matter how many rows you add to DataTable, it only stays in memory of
running computer. You must specifically update the changes you mad to the
database back to database, using DataAdapter, or Command. Look into
DataAdapter.Update() method, it is what yo are going to use, as starter.
 
P

Paolo

I think the problem is you should Update the dataSet... Try with
myDataAdapter.Update(mydataTable);
You should create the INSERT, UPDATE and DELETE commands for the
Update method to work...

Paolo
 
B

bgundas

Hello, I need immediate help with this problem.
From C# code I am trying to call a stored procedure, which is in a
oracle 8i db.





First of all here is the definition of the function(oracle function).

//==================================================================

FUNCTION INSERT_COMMENTS( iv_acc_id IN VARCHAR2,

iv_user_id IN VARCHAR2,

iv_comment IN VARCHAR2 )

RETURN BOOLEAN;

//==================================================================









My Catch catches this error code coming for Oracle side.

//==================================================================

:In insertComments2 method => ORA-06550: line 1, column 7:

PLS-00306: wrong number or types of arguments in call to
'INSERT_COMMENTS'

ORA-06550: line 1, column 7:

PL/SQL: Statement ignored

//==================================================================











And here is my C# code that tries to make the call to the oracle.

//==================================================================

public static void insertComments2(string accID)

{

try

{

string useridv = "DAYBREAK";

string STR_COMMMENT = "Wellcome letter has been
generated";


//==============================================================================

//create an instance of the command object
giving the procedure name

OleDbCommand sqlCmd2 = new
OleDbCommand("ACCP50.INSERT_COMMENTS",myConn) ;



// Define the command type u r executing as a
Stored Procedure.

sqlCmd2.CommandType =
CommandType.StoredProcedure ;




sqlCmd2.Parameters.Add("iv_acc_id",OleDbType.VarChar,20);

sqlCmd2.Parameters["iv_acc_id"].Direction =
ParameterDirection.Input ;




sqlCmd2.Parameters.Add("iv_user_id",OleDbType.VarChar, 20);

sqlCmd2.Parameters["iv_user_id"].Direction =
ParameterDirection.Input ;




sqlCmd2.Parameters.Add("iv_comment",OleDbType.VarChar,40);

sqlCmd2.Parameters["iv_comment"].Direction =
ParameterDirection.Input ;



sqlCmd2.Parameters.Add("RETURN
BOOLEAN",OleDbType.Boolean);

sqlCmd2.Parameters["RETURN BOOLEAN"].Direction
= ParameterDirection.ReturnValue;



detailLog(accID,w);



//sqlCmd2.Parameters["RETURN
BOOLEAN"].Direction = ParameterDirection.ReturnValue;

//sqlCmd2.Parameters["RETURN BOOLEAN"];



sqlCmd2.Parameters["iv_acc_id"].Value = accID;
;



sqlCmd2.Parameters["iv_user_id"].Value =
useridv;



sqlCmd2.Parameters["iv_comment"].Value =
STR_COMMMENT;



// execute the stored procedure

sqlCmd2.ExecuteNonQuery();



// if ((string) (sqlCmd2.Parameters["RETURN
BOOLEAN"].Value.ToString()) == "true")

// detailLog(" Success. Comments has been
inserted successfully.", w);

// else

// detailLog(" FAILED. Comment insertion
failed.", w);



}

catch (Exception error)

{

detailLog("In insertComments2 method => "
+error.Message, w);

System.Console.Write(error.Message);

}

}



//==================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top