|
Hello everyone,
I have a DataGridView controll which is populated by a table from a remote database. One of the Columns contains images which I am using the following line of code to access the images in the DataGridView.
System.Drawing.Image itemOriginalImage = (Image)dataGridView1.Rows[ItemRowIndex0].Cells["item_image"].FormattedValue;<br />
I wish to remove the DataGridView and replace it with a DataTable. I was wondering how I can access the image column in the DataTable?
I am using this code but I am unable to set the format right.
System.Drawing.Image itemOriginalImage = (Image)myTable.Rows[ItemRowIndex0].ItemArray.GetValue(6).<br />
I get the following error for the above line of code. "Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Image'."
Can someone be kind enough to tell me how I can access the image in my DataTable?
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
Use
System.Drawing.Image _image = System.Drawing.Image.FromStream( new System.IO.MemoryStream( (byte[])myTable.Rows[ItemRowIndex0].ItemArray.GetValue(6)) );
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
I have a string strA = "12 MyAddress"
strB = "Your Name"
I want to get the first char of string and want to know weather it is integer between 1-9 or char between A-B.
How can I do that.
seema
|
|
|
|
|
The string class provides a handy little Substring function. You can cast it to a char, and the char class provides functions like IsDigit to help. Have a look at the documentation for these classes to get a clear idea of exactly what you need to do.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
char c = strA[0];
if (c >= '1' && c <= '9') {
} else if (c >= 'A' && c <= 'B') {
}
|
|
|
|
|
In C# or VB.NET ? Please don't crosspost.
You can do this:
if (Char.IsDigit(strA[0]) || strA[0] == 'A' || strA[0] == 'B')
{
}
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Since you have cross-posted in three forums you are being sent to the corner where I will whip you virtually with my Wired magazine until you beg for forgiveness.
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
hi
I got a problem in inserting new rows to a datatable.How can I insert dates in a data table using DB2.
Here is some code...
DB2Connection conn = new DB2Connection(connectionString);
DB2DataAdapter DataAd= new DB2DataAdapter(select, conn);
DataSet ds=new DataSet();
DataAd.Fill(ds, "Table Name");
Datarow dr = ds.Tables["Table Name"].NewRow();
DB2Command aCommand = new DB2Command(select, conn);
aCommand.CommandType = CommandType.Text;
aCommand = new DB2Command("INSERT INTO CL.VSCHTM("ST_DTE")"
"VALUES ("#" + dr["ST_DTE"]+"#",conn);
DataAd.InsertCommand = aCommand;
DataAd.Update(ds, "Table Name");
aCommand.Parameters.Add(new DB2Parameter("ST_DTE",DB2Type.Date, 0, "ST_DTE"));
aCommand.UpdatedRowSource = UpdateRowSource.OutputParameters;
It doesn't add new row ,any help??
kidus
|
|
|
|
|
Is the datetime the min value in .net? There is a chance that db2 doesn't support it. I know sql server does not. I would think if the row doesn't get inserted there must be an error message. Have you tried to do the insert outside of .net to see if it works?
Ben
|
|
|
|
|
I trying to interact with a Microsoft Access Database in an application. Interactions include creating, deleting, and editing entries.
In Visual C# Studio, I have created a connection to the database, but I can't figure out what to do from there. Is there a way to cycle through the rows and columns in a database table using a for or foreach loop? I'm thinking it has something to do with the DataSet and other associated classes.
If I had a sig, it would probably go here.
|
|
|
|
|
Well, you can extract rows into a dataset and then use a foreach on the DataRows. For instance:
foreach (DataRow dr in dsDataset.Tables[0])
{
} Alternatively, you can pull the data out with a DataReader and loop through them using:
while (dr.MoveNext())
{
} Note that this is sometimes called a firehose cursor (something you may want to google).
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
That's what I was thinking, but how do I extract rows into a dataset?
If I had a sig, it would probably go here.
|
|
|
|
|
Well, one way to do this is:
DataSet ds ;
using (OleDbConnection conn = new OleDbConnection("myConnectionDetails"))
{
using (OleDbDataAdapter cmd = new OleDbDataAdapter ("myCommand", conn))
{
conn.Open();
try
{
cmd.Fill(ds);
cmd.Close();
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}
}
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks, I'll try that!
Hippophobia- Fear of horses. What... What?
|
|
|
|
|
And is there a way to put the data from the DataSet back into the database?
Hippophobia- Fear of horses. What... What?
|
|
|
|
|
I recommend buying a book on ADO.NET, and perhaps one on SQL ( from the sounds of it )
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi .I have following problem with DataGridView. I use DataGridView bound to collection of objects. One of the properties is of boolean type. It is bound to CheckBoxColumn. I would like to display number of rows that are checked immediately after user checks one of the rows. Unfortunately value is pushed to underlying source only after user leaves edited cell. Is there any way how to find how many rows is checked right after box is clicked.
|
|
|
|
|
does anyone know how to loop through a binding source?
so far i have been working with the code
foreach (DataRowView invoiceRow in invoicebindingsource)
{
}
but what if i only want to check one column? I am also a little unclear on how to address that info in the cell i am currently looking at
Thanks for any help you can give
|
|
|
|
|
crash893 wrote:cell i am currently looking at
what does "looking at" mean?
|
|
|
|
|
test or manipulate
messagebox.show(something.tostring())
i am also trying to figure out how to do something like
if something.tostring() containes stringtext
{
replace something.tostring with stringreplace
}
|
|
|
|
|
crash893 wrote: test or manipulate
so if replace "looking at" in your first post with "test or manipulate".....
crash893 wrote: I am also a little unclear on how to address that info in the cell i am currently testing
I struggle to understand your posts. All I can do is guess that you are asking how to access the "columns" in the DataRowView . I really hope this is a school project. Anyway, I recommend you "read" some documentation on DataRowView from the MSDN Library which is available online from Microsoft. Also there are many MANY articles here on CodeProject that contain sample code for working with Database related issues. I would bet some of them show how to access columns of a DataRowView.
|
|
|
|
|
Hi
Sometimes Paint event handler throws exception "Current object used elssewhere"...
For example:
private blablabla_Paint(object sender, PaintEventArgs e)
{
Graphics gr = e.Graphics;
...
gr.DrawLine(...); //<---- Usually it happens here.
}
locking of "gr" object hasn't helped... what can I do with it???
Sorry for my bad English... =)
|
|
|
|
|
Oleg Mehechkov wrote: gr.DrawLine(...); //<---- Usually it happens here
if that is where it happens, you should show the line as is, and not part of it and
some elipses. Actually, you should show the entire method.
How do you expect anyone to help you now ?
show the exact line; and if it contains operators (new, +, &, /, whatever) split
the line, introduce local variables, and let the exception pinpoint which part of the
original line got bombed.
Oleg Mehechkov wrote: Usually it happens here
And where else does it also happen ? Show us that method too !
|
|
|
|
|
You're not trying to do graphics processing on multiple threads are you? This is, quite often, the cause of the InvalidOperationException that you are seeing.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
And how I can correct this bug???
Sorry for my bad English...
|
|
|
|