Hi ,
I am trying to remove rows from a table using :
DataTable.Rows. RemoveAt(int index);
or
DataTable.Rows. Remove(DataRow row);
syntax.
I am able to run my test program successfully but none of the rows get
deleted. It works fine by using a delete SQL statement with a Command
object but I am trying to learn other methods todo the same. The
sample code : -
// dataset
DataSet ds = new DataSet() ;
// loads result set into dataset
oleDbDataAdapte r.Fill(ds);
// get the table; since we have only one table
DataTable workTable = ds.Tables[0];
// give it a name
workTable.Table Name = "coffee";
// how many rows do i have before removing
Console.WriteLi ne("Number of rows: {0}", workTable.Rows. Count );
for (int i=0; i < workTable.Rows. Count; i++)
{
DataRow myRow = workTable.Rows[i];
int sup_id = Convert.ToInt32 (myRow["sup_id"]);
if ( sup_id == 120 )
{
Console.WriteLi ne(sup_id);
workTable.Rows. RemoveAt(i);
workTable.Accep tChanges();
}
}
/***
foreach (DataRow myRow in workTable.Rows)
{
int sup_id = Convert.ToInt32 (myRow["sup_id"]);
if ( sup_id == 120 )
{
Console.WriteLi ne(sup_id);
workTable.Rows. Remove(myRow);
workTable.Accep tChanges();
}
}
*** /
// how many rows after removing
Console.WriteLi ne("Number of rows: {0}", workTable.Rows. Count );
}catch(OleDbExc eption e)
{
Console.WriteLi ne(e.StackTrace );
}
How do I commit the changes such that the rows are deleted from the
database;
Thx in advance
DN
dn********@will iamoneil.com (Deepankar) wrote in message news:<c5******* *************** ****@posting.go ogle.com>...
Hi Miha,
Thx for the site. It helped to solve the problem.
Cheers
DN
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:<uo******* *******@tk2msft ngp13.phx.gbl>. .. Hi,
Check out this article:
How to read and write a file to or from a BLOB column by using ADO.NET and
Visual C# .NET
http://tinyurl.com/2nvn5
--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com
"Deepankar" <dn********@wil liamoneil.com> wrote in message
news:c5******** *************** ***@posting.goo gle.com... Hi,
I was trying to change an example for SQL Server to work with Access
db to insert image data. I have everything working except getting the
OleDbParameter type for the image column.
The table in access is :
img (
id number ,
name Text,
img number [Byte]
);
code :
===========
//....
byte[] photo = GetPhoto(photoF ilePath);
OleDbConnection Conn = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0; User Id=;Data
Source=C:\\temp \\testdb.mdb");
OleDbCommand addJpg = new OleDbCommand("u pdate img set img =
@Photo where id = @id", Conn);
OleDbDataAdapte r MyDataAdapter = new OleDbDataAdapte r();
MyDataAdapter.I nsertCommand = addJpg ;
OleDbParameter id = new OleDbParameter ("@id", OleDbType.Integ er)
;
id.Value = 1;
OleDbParameter ph = new OleDbParameter ("@Photo",
OleDbType.VarBi nary, photo.Length) ;
ph.Value = photo;
MyDataAdapter.I nsertCommand .Parameters.Add (ph);
MyDataAdapter.I nsertCommand .Parameters.Add (id);
// connect
Conn.Open();
// insert
addJpg.ExecuteN onQuery();
Conn.Close();
//........
Any pointers...
Thanx in Advance
DN