|
There are pretty much only two errors you can generate easily from
s[i] = dr[0].ToString(); One is an access violation, and implies that the string array "s" is not big enough to hold the data.
The other is a null reference exception, which implies that dr[0] returns a null.
Since you have said it is a null reference error you are getting, it must be dr[0] is null. Add a check for this in your code, and do not process that line any further:
if (dr[0] != null)
{
s[i] = dr[0].ToString();
}
What are you actually trying to achieve? Is this winforms, or ASP? If you are writing to a Word document, why are you using httpContext? Why not use Interop?
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
But I do not think dr[0] is null because if i put the following code, it displays the data.
while (dr.Read())
{
HttpContext.Current.Response.Write(dr[0]);
}
so I dont know where the error is ?
suchita
|
|
|
|
|
Well I tried to use another way. I showed it first to the datagrid and after i try to show it in word file. well that one works well. But here my problem is since I am showing them in datagrid, when it comes in word document, it shows the same way as in datagrid. But I want to have some formatting on it. Like for example, i want some field of the datagrid on the top where as somefield on the other side. Can I be able to do that in word document ?
suchita
modified on Thursday, July 22, 2010 10:28 AM
|
|
|
|
|
I'm not sure if I can get the answer on this...
I'm trying to find out of Visual Studio 2010 has the line to show location of open/closing bracket as seen on the photo... (this was from NotePad ++)
This will help me to see better where the open/close bracket belongings, rather than click on the closing bracket and look for the highlighted opening bracket.
Oh, speaking of photo, how do I attach the pix on this?
the line on opening/closing bracket can be seen on Notepad++ software.
I'll do the ascii text here... <sigh>
for (int i = 0; i < 5; i++)
{
| if (i == 2)
| {
| | ....
| | ....
| }
| else
| <throw exception>
}
|
|
|
|
|
I personally use end of brace comments. Also, if a method is larger than the screen, it is too large. With this rule of thumb and a preference for a lot of little methods deep nesting of loops can be avoided. As for getting visual studio to do what you want, good luck. It can barely manage MS preferences
for (..){
;
}
|
|
|
|
|
It is certainly available for VS 2008 as part of the MS extension CodeRush[^], but I don't know if that will work in VS 2010 (I'm waiting for SP1 before I think about upgrading). Worth a try though.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Even though I use that brace-placement format, that's one of the things I don't like about Notepad++
It's not as flexible as VS' way of highlighting matching items.
|
|
|
|
|
0I have this date in xml web services..
7/19/10 5:00 PM Local Time
how can I convert it to:
Mon 19 Jul 2010 Local Time
|
|
|
|
|
Try:
DateTime d = DateTime(2010, 7, 19, 17, 0, 0);
string s = d.ToString("ddd dd MMM yyyy");
See Formatting a DateTime for display[^] for full details
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
How about you drop the "Local Time" and use DateTime.Parse/ParseExact/TryParse/TryParseExact ?
|
|
|
|
|
hi
how to open www.google.com and insert any text to the textbox search (only for show)
or another website that has textbox ?
in C# Winforms ?
thank's in advance
|
|
|
|
|
Hi,
not sure what you want.
1.
http://www.google.com/#q=any+text[^]
2.
Google Search has an API
3.
If there's only one editable control on a web page, it is likely to have the focus, so simply send some text (SendKeys) to the app.
|
|
|
|
|
|
Hello Everyone,
I am trying to extract the contents of the table from a static HTML file.
Program is almost giving the expected output.
Program :-
class Program
{
static void Main()
{
StreamReader str = new StreamReader("C:\\AllRoles.html");
string SFile = str.ReadToEnd();
Regex regex = new Regex(
@"<tr>(\s* <td[^>]*> \s* (?<value>[^<]*?) \s* </td> )+ \s*</tr>",
RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach( Match m in regex.Matches( SFile ) )
{
foreach( Capture item in m.Groups["value"].Captures ) {
Console.WriteLine( item.Value );
}
Console.WriteLine( );
}
Console.ReadLine();
}
}
I am facing one problem there is a comment in between the table content
HTML File :-
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tbody><tr>
<td class="columnheading" nowrap="nowrap">Last Name</td>
<td class="columnheading" nowrap="nowrap">First Name</td>
<td class="columnheading" nowrap="nowrap">Role</td>
<td class="columnheading">Term</td>
<td class="columnheading">Company</td>
</tr>
<tr>
<td valign="top">
<!-- Logic Here-->
Gottlieb
</td>
<td valign="top">Pradep</td>
<td valign="top">President
</td>
<td valign="top">8/15/2009 - 9/1/2010</td>
<td valign="top">DSCMIT</td>
</tr>
<tr>
<td valign="top">
<!-- Logic Here-->
Rajesh
</td>
<td valign="top">H</td>
<td valign="top"> President
</td>
<td valign="top">8/15/2009 - 8/14/2010</td>
<td valign="top">BHSIT</td>
</tr>
I am getting the Output as
Last Name
First Name
Role
Term
Company
and it stops at this line <!-- Logic Here-->
Can anyone please help me to solve this problem.
Thanking you,
Naveen HS
|
|
|
|
|
I would try adding RegexOptions.MultiLine
|
|
|
|
|
Hi all,
I am looking for a library which can perform the following tasks:
- Taks a description of a method call (e.g. Method name, Parameter name and parameter Value)
- Parse the method description
- invoke a method depending on the parsed description.
- encode the result of the method invocation and pass it as text back.
I know that all of this isn't rocket science, the question is: Is there a library that I can use.
best regards
Lars
#pragma error( disable : * )
|
|
|
|
|
Reflection. But it will also need a Type to operate on.
|
|
|
|
|
Hi,
I need to call a function written in C# from the unmanaged code.
The code from where I have to call the function is purely written in VC++ and it come in the unmaged part of the solution code.
Most of the solution is written in C# .NET 3.5.
Please help me out.
Thanks In Advance
Abbas
|
|
|
|
|
So you need P/Invoke, make sure any objects (arrays) you pass get properly pinned, and pass a delegate. All you need should be in my article here[^].
|
|
|
|
|
To call the method directly, you're realistically limited to using COM. This means you need to expose you .NET object as a COM object and import the type library into your VC++ application.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
I am downloading a binary document from sql server and depending upon my file extn it should either open doc txt or image.For txt it is working fine while for word it is saying"Word experience an error in opening the file".While for jpg image viewer is opening but no image is there
What could be the reason
I am using windows application in C#
|
|
|
|
|
Looks like your file is not getting downloaded completely.
Post some code here - maybe someone can help you.
|
|
|
|
|
if (dt.Rows.Count > 0)
{
result = (byte[])dt.Rows[0].ItemArray[0];
filetype = (String)dt.Rows[0].ItemArray[1];
}
String new_FileName = Path.ChangeExtension(Path.GetTempFileName(),filetype);
File.WriteAllBytes(new_FileName, result);
System.Diagnostics.Process.Start(new_FileName);
THis is my code
i will get bytes in result array and filetype also.SO depending on that I am opening the file to display the data
|
|
|
|
|
In my case the same is working properly but I am using dt.rows(0)("FieldName") instead of Itemarray . May be there is problem while saving it into database.
|
|
|
|
|
I use coloumn name also .But same happening.
|
|
|
|