|
Instead of casting to Int32 you have to first cast to System.Data.DataRowView. If you have this you can use its indexer to access the element you need. After that cast this element to Int32 and you are done.
|
|
|
|
|
how to do that can u pls explain i am new to C#
|
|
|
|
|
are you getting this problem only when the form is loading??
Afzal Hassen
|
|
|
|
|
As Im really in a hurry here just a small snippet:
DataRovwView drv = (DataRowView)this.cmbSubDiagnosis.SelectedValue;
int myIntValue = (int)drv[IndexOrNameOfTheColumnYouWishToAccess];
|
|
|
|
|
Your core problem is that you're shoving a datarowview into the value, the problem really is when you set the data source. You need to tell the combo which property to use to set the value for each row. The problem has nothing to do with the event. You have a datarowview in the value, you cannot magically turn it into an int, you need to either get it out as a datarowview ( which is what it is ) and then work out where your number is or, preferably, you need to fix the code that sets the datasource, so that it does in fact contain an int as you were hoping.
In general, these 'please help me, something blows up' posts are useless, look how long it took us to get to the heart of the problem. You should learn to use your debugger. You'll get your answer a lot quicker if you post something like 'this line throws an invalid cast exception and the value in the row that I'm trying to cast is a datarowview.' A few seconds in the debugger will tell you that, and as you learn C#, that's the path you'd follow to fix the problem, by first knowing what it is.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks
i will try to follow ur instructions .
monica
|
|
|
|
|
I know you take a performance hit if you make your methods virtual, but do you take a similar hit when you use abstract methods
|
|
|
|
|
Abstract methods are also virtual, it's just that they don't have any implementation in the base class. If you look into the generated IL, you'll see that they are declared virtual (plus abstract) and that method calls are translated to callvirt, which is IL speak for calling a virtual method.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I have a URL that I can open in the browser, but System.Uri removes a slash when it encounters an extra http: in the URL.
Here is the URL:
http://citeseer.ist.psu.edu/rd/55811103,124,1,0.25,Download/http://citeseer.ist.psu.edu/cache/papers/cs/1473/http:zSzzSzmaui.theoinf.tu-ilmenau.dezSzforschungzSzlinkszSz..zSzdoczSzhybrid_automata.pdf/alur92hybrid.pdf
System.Uri changes the above URL to (notice that http:// after Download is changed to http:/)
http://citeseer.ist.psu.edu/rd/55811103,124,1,0.25,Download/http:/citeseer.ist.psu.edu/cache/papers/cs/1473/http:zSzzSzmaui.theoinf.tu-ilmenau.dezSzforschungzSzlinkszSz..zSzdoczSzhybrid_automata.pdf/alur92hybrid.pdf
As a result, I get NameResolution exception when making HttpWebRequest.GetResponse() calls.
|
|
|
|
|
It assumes that you were wrong as it may not come 2 httpS in the url,
you may resolve this by sending it as a query string ,if you own this site.
|
|
|
|
|
|
string aa = "\document\test";
aa = aa.Replace("\", "\\"); --- this line C# doesn't like it??
I want to replace '\' in string aa to "\\". How to do it?
|
|
|
|
|
You have to escape your chars
Alex Korchemniy
|
|
|
|
|
I suspect the problem is that \d and \t are valid escape values, so you've not realised the problem. To put a \ in your string, either put two or, ( my preferred option ), use @. With @ at the start, everything is literal, the only escape is double quotes to do quotes.
string aa = "\document\test";
The value here is ocument test, where the spaces are a tab
string aa = @"\document\test";
string aa = "\\document\\test";
These both set the string as you'd expect
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If you have it already and want it to be replaced now,you may use the StringBuilder class that will assure that it's been replaced.
|
|
|
|
|
string aa = @"\document\test";
aa = aa.Replace(@"\", @"\\") ;
Sanjay Sansanwal
www.sansanwal.com
|
|
|
|
|
<br />
string aa = @"\document\test";<br />
<br />
aa = aa.Replace("\\", "\\\\");<br />
<br />
aa = aa.Replace(@"\", @"\\");<br />
<br />
<br />
Trick:
If U want to use \ in strings U must duplicate it, or use @ before teh string.
I hope it helps.
Nemo
|
|
|
|
|
Yeah so I created a nice little Web Service that returned a custom class called Site which has 3 strings and an int. I kept getting:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type PortalService.Site was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
And I used both XmlInclude and SoapInclude to no avail. So I said screw it and created a string with a delimiter that I could parse when it returned to the client. Perfect. Except now when I call the WebService, the webpage's graphics don't load completely and at random. I suppose this perhaps attributed to the fact that I just did <% Function() %> since the basic Repeater did not suite my needs. Any suggestions?
|
|
|
|
|
I get a compiler error that not all code paths return an error. I'm fairly new at C# so did something change from MFC to C#?
<br />
public bool ConfirmSQLServer()<br />
{<br />
String SrvrName;<br />
SQLutilz sie = new SQLutilz();<br />
<br />
IniFile ini = new IniFile("C:\\Larimore\\Prog\\LA.CFG");<br />
SrvrName = ini.IniReadValue("DATABASE","Server");<br />
ResultsLst.Items.Add("Database Server: " + SrvrName, 0);<br />
String[] SrvrLst = sie.EnumerateSQLServers();<br />
<br />
for (int i = 0; i<SrvrLst.Length;i++)<br />
{<br />
MessageBox.Show(SrvrLst[i].ToString()+ " " + SrvrName.ToUpper());<br />
if (SrvrName.ToUpper().CompareTo(SrvrLst[i].ToString())== 0)<br />
return true;<br />
else<br />
return false;<br />
}<br />
}<br />
<br />
<br />
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Take your return statements out of the for loop.
Example)
bool retValue = false;<br />
for (int i = 0; i {<br />
MessageBox.Show(SrvrLst[i].ToString()+ " " + SrvrName.ToUpper());<br />
if (SrvrName.ToUpper().CompareTo(SrvrLst[i].ToString())== 0)<br />
retValue = true;<br />
break;<br />
}<br />
return retValue;
Eddie
|
|
|
|
|
C# sucks at working out that all code paths do indeed return a value, although in this case, you'll return no matter what on the first iteration.
You should set a return variable with a default value, and return it at the end, change it on the way through if need be. For example, I'd set a bool value to indicate success to false, and reset it to true only when everything had worked as expected.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
C# sucks at working out that all code paths do indeed return a value
Hmmm... I always had the feeling C# was rather clever doing this. Why exactly do you think C# 'sucks' in this point?
|
|
|
|
|
An example that hit me recently was when I was trying to use an if-elseif construct to return a different result for each value of an enum type. despite having a branch with a return for each possible value c# refused to accept that it always would return a value.
|
|
|
|
|
To be honest, I would think it would be more efficient to code it like I have. No memory is taken up by a BOOL in my code that you would in the earlier suggestion.
Thanks for all the help guys. Some things C# is really good at, other things it's not.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Because I've written code where all paths return a value, but they are all in an if/else situation, and the compiler has barfed.
Christian Graus - Microsoft MVP - C++
|
|
|
|