|
i sent full article of this code to CODEPROJECT .
after that my article being accepted, you can use of them.
but code is like this:
you must use of NORTHWINFD Database
private void button1_Click(object sender, EventArgs e)
{
SqlConnection co = new SqlConnection();
co.ConnectionString = @"Server=.\SQLEXPRESS;initial catalog='NORTHWND.MDF';Trusted_Connection=Yes";
SqlCommand cmdSelect = new SqlCommand();
cmdSelect.Connection = co;
cmdSelect.CommandText = "SELECT (FirstName+' '+LastName) AS Fullname FROM Employees";
SqlDataAdapter da = new SqlDataAdapter(cmdSelect);
DataTable dt = new DataTable();
co.Open();
da.Fill(dt);
comboBox1.DataSource = null;
comboBox1.DataSource = dt;
comboBox1.ValueMember = "Fullname";
co.Close();
}
private void button2_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)comboBox1.DataSource;
DataRow dr = dt.NewRow();
dr[0] = "< select item >";
dt.Rows.InsertAt(dr, 0);
comboBox1.DataSource = dt;
comboBox1.SelectedIndex = 0;
}
|
|
|
|
|
Hi all
i am doing export to excel operation using below code.
public void ExcelExport(System.Data.DataTable tblExportData, string TempFilePath,string userInfo,bool headerStatus)
{
try
{
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Workbooks.Open(TempFilePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//Writing Header in Excel
if (headerStatus == true)
{
for (int i = 0; i < tblExportData.Columns.Count; i++)
{
excelApp.Cells[7, i + 1] = tblExportData.Columns[i].ColumnName;
}
}
//Writing Data in Excel
for (int i = 1; i <= tblExportData.Rows.Count; i++)
{
for (int j = 0; j < tblExportData.Columns.Count; j++)
{
string colName = tblExportData.Columns[j].ColumnName;
excelApp.Cells[i + 7, j+1] = tblExportData.Rows[i-1][colName];
}
}
//Create a worksheet object
Microsoft.Office.Interop.Excel.Sheets sheets = excelApp.Worksheets;
//from the collection of worksheet select one worksheet
Microsoft.Office.Interop.Excel.Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
//select the cell in the worksheet
Microsoft.Office.Interop.Excel.Range myCell1 = (Microsoft.Office.Interop.Excel.Range)mySheet.get_Range("A6", "A6");
myCell1.Value2 = userInfo;
myCell1.Font.Color = System.Drawing.Color.Black.ToArgb();
excelApp.Visible = true;
}
catch (Exception ex)
{
}
}
it's working fine in local. but when i deployed this on server(e.g.relience server) then it stops to work. i mean exporting to excel not working. Even it's not generating any error and page is redirecting also. can any one help me please.
thanks to you all in advance.
Binod
|
|
|
|
|
Is excel installed on the server? Also improve your error handling, any errors generated are lost with your code.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I assume that this is being done in ASP.NET??
There's a few things you need to do to ensure that the application works. Note that the official MS line is that Excel is not a server component so they don't provide any support in that respect.
First things first - you'll need to have Excel installed on the server along with the interop assemblies.
Secondly, you need to ensure that the DCOM settings for Excel allow it to be launched from within IIS. You'll need to know what identity your web application will launch Excel as (it's usually NETWORK SERVICE, ASPNET or IUSR_<machinename> depending on your settings and version of IIS). To do this:
Start menu -> Run -> dcomcnfg.exe
Component Services -> Computers -> My Computer -> DCOM Config
Microsoft Excel Application -> Right Click, Properties -> Security Tab
From this tab you need to change the launch, access and configuration permissions to allow full and remote access to the user account you located above.
Next you'll need to do:
Properties -> Identity
select 'Interactive User'.
Finally you'll need to ensure that the webpage launching excel is correctly configured. The interop component expects to be run in a single thread apartment (STA) but ASP.NET defaults to multiple threads (MTA). You can force the use of an STA by including
AspCompat="true"
in the page directive header.
Finally you'll need to modify your web.config file to include a
identity impersonate="true"
section under system.web.
From the way you've written this code, I think you'll end up running into a problem that the instance of excel remains in memory after each export is performed. I don't have time to go into the detail but the problem is that you're not cleaning up objects once they've been disposed of. Note that when you create the export you're actually creating a number of objects (Application, Workbook, Worksheet, Range - at the very least) and all these need cleaning up.
There's articles out there on the web that will explain how to do this though it might take you a bit of trial and error.
Hope that helps!
It definitely isn't definatley
|
|
|
|
|
When one is writing an email in the "To:" textbox, gmail gives you choices of similar coincidences in a combobox-like way:
http://www.youtube.com/watch?v=bWy9SrhUpOM[^]
With the Combobox' AutoCompleteMode set to Suggest I can change the current text of the combobox, but how can I make it add the selection to the end of the current string?
modified on Wednesday, June 17, 2009 1:25 AM
|
|
|
|
|
Trun Yes on the AutocompleteMode and Autocomplete Source(SuggestAppend) properties
|
|
|
|
|
i gor error telling missing refference in PixelData...
may i know what refferance...?
i'm tring to do QR barcode decoder...
private void button2_Click(object sender, EventArgs e)
{
unsafe
{
Image image = Image.FromFile("D:\\1.JPG");
BitmapData bd = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
int sourceWidth = image.Width * System.Runtime.InteropServices.Marshal.SizeOf(typeof(PixelData));
if (sourceWidth % 4 != 0)
sourceWidth += (4 - (sourceWidth % 4));
Byte* bitmapBaseByte;
bitmapBaseByte = (Byte*)bd.Scan0.ToPointer();
PixelData* pPixel;
for (int y = 0; y < height; y++)
{
pPixel = (PixelData*)(bitmapBaseByte + y * sourceWidth);
for (int x = 0; x < width; x++)
{
intImage[x][y] = (int)((0xff << 0x18) | (pPixel->red << 0x10) | (pPixel->green << 8) | pPixel->blue);
pPixel++;
}
}
image.UnlockBits(bd);
}
anyone just help me....thanks...
A S E L A
modified on Wednesday, June 17, 2009 2:10 AM
|
|
|
|
|
Is there any way to know which the PDF is currently opened. If there are many instances of Acrobat Reader are obtained, then also, I have to get all the PDF documents opened.
How can I do this?
Don't Say that "You can't do", I think there will be definitely something to do this.
any suggestion can be posted here.
Thank You...
|
|
|
|
|
I want to put this line of numbers:
9 1 10 10 8 2 7 2 9 0 10 9 1 8 2 10 7 2 -1
into a 19 number array array[19]
I am reading those numbers from a text file, but I don't know how to assign them to an array?
This is what I have so far, its reading from the text file....
<br />
int main(void)<br />
{<br />
<br />
char ch;<br />
char string [256];<br />
int i;<br />
int raw;<br />
FILE *fin, *fout;<br />
fin=fopen("g:/cfinal/bowlin.txt", "r");<br />
fout=fopen("g:/cfinal/bowlout.txt", "w");
|
|
|
|
|
You have the wrong forum, this forum is for C#
only two letters away from being an asset
|
|
|
|
|
Hello all
I have a mysql table with some rows in it that contain a path to a jpg file.
Here is a example of the path:
images/portfolio/lille_ilveaWebshop.jpg
The file excists on the webhost so that is not a problem.
I am loading the jpg file into a bitmap in a foreach.
It works fine when I am on a local server, but when I upload it to my webhost it says:
<quote>Server Error in '/' Application.
Out of memory.
Exception Details: System.OutOfMemoryException: Out of memory.
[OutOfMemoryException: Out of memory.]
System.Drawing.Bitmap..ctor(String filename) +376480
Referencer.Page_Load(Object sender, EventArgs e) +561
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627</quote>
I cant seem to figure out just why it would do that.
Here is the code I am using:
foreach (
DataRow Row in objPortFac.VisReference(refKatID).Rows)
{
// Create a new bitmap with the path from the row
// fldStortBillede is the field that contains the path
Bitmap objStortBillede = new Bitmap(Server.MapPath(Row["fldStortBillede"].ToString()));
// Dispose the bitmap after use
objStortBillede.Dispose();
}
Any suggestions?
|
|
|
|
|
Hi,
some image operators (e.g. Image.FromFile) throw an OOM Exception when the data is not valid. I don't know what Server.MapPath is assumed to do, nor how valid its result is. Split the statement in simpler ones and debug.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
The "new bitmap" needs a full path an images/something/blah.jpg doesnt work.
I am using Server.MapPath to find the full path
|
|
|
|
|
Have you checked the value of Server.MapPath(Row["fldStortBillede"].ToString() ?
MSDN: "For security reasons, the AspEnableParentPaths property has a default value set to FALSE. Scripts will not have access to the physical directory structure unless AspEnableParentPaths is set to TRUE."
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
The value on localhost is:
D:\Skole\DotNet\Portfolio\Portfolio\images\portfolio\stor_cronaldoHjemmeside.jpg
And on the webhost it is:
d:\web\localuser\dumpen.dk\public_html\images\portfolio\stor_cronaldoHjemmeside.jpg
It works with 2 or 3 images but with more then that the error occours
|
|
|
|
|
is it always the same image that fails, if so it got damaged. try changing the order just to see what happens.
are these images large, compared to your system (is it a mobile Windows system with limited RAM?).
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
I'm also having the same Problem.
In my local it is working properly. But in server, it is throwing out of memory exception.
i got this exception even though the memory is available in server.
Graphics g = Graphics.FromImage(source);
try
{
g.DrawImageUnscaled(original, 0, 0);
}
finally
{
((IDisposable)g).Dispose();
}
This is the code i'm using.
Any solutions to this issue?
Thanks in advance
|
|
|
|
|
insufficient information.
IMO DrawImageUnscaled is more critical than DrawImage, as the resolution may be screwed inside the image (both source and original). Try DrawImage instead. And log all image parameters, to see if there ever is anything abnormal.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Luc Pattyn wrote: some image operators (e.g. Image.FromFile) throw an OOM Exception when the data is not valid. Nice. 8 years later, and this post was quite relevant for me, in that it really wasn't an OOM error.
|
|
|
|
|
Today, I need to fix that statement; it should read:
some image operators (e.g. Image.FromFile) MAY throw an OOM Exception when the data is not valid.
There is no guarantee an OOM will occur on every damaged image!
Luc Pattyn [My Articles]
The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.
|
|
|
|
|
Is there an already implemented way to get all the nodes within a treeview? including the childs,
for example if you have a treeview like
+father
++child
I would like to get a TreeNodeCollection with this two..
Should I create my own MyTreeView : TreeView implementing a method?
|
|
|
|
|
If I understand what you want correctly, without walking the entire tree yourself, no there isn't.
Every TreeNode supports its own TreeNodeCollection. So you just have to walk the entire collection of each node and add it to your seperate TreeNodeCollection.
|
|
|
|
|
No, I don't think such method exists. You don't have to create a custom tree view for this, just write an extension method[^] (assuming you're using C# 3.0).
Eslam Afifi
|
|
|
|
|
public void GetNodes(TreeNodeCollection tc)
{
foreach (TreeNode tn in tc)
{
MessageBox.Show(tn.Text);
GetNodes(tn.Nodes);
}
}
I know nothing , I know nothing ...
|
|
|
|
|
Ok I did it this way, any comments?
<pre>
public class G31TreeView : TreeView
{
private static TreeNodeCollection allNodes;
/// <summary>
/// Returns all nodes, including childs (a flattened tree)
/// </summary>
public TreeNodeCollection AllNodes {
get
{
allNodes = new TreeNodeCollection();
return BuildAllNodesList(this.Nodes);
}
}
/// <summary>
/// Builds the list of all nodes recursively
/// </summary>
/// <param name="tnc">The initial node to begin the build</param>
private void BuildAllNodesList(TreeNodeCollection tnc)
{
foreach (TreeNode tn in tnc)
{
// If the list hasnt added the current node we add it.
if (!allnodes.Contains(tn))
{
allnodes.Add(tn);
}
// Childs of current tn
BuildAllNodesList(tn);
}
}
}
</pre>
|
|
|
|