|
H.Goli wrote: Is there any way to do this? Create a property called "Id" in MyClass and have it return the Id of the CurrentItem object?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Several things in your code "jump out at me" as kind of ... confusing:
1. you made the constructor of MyClass private: so you cannot create a new instance of MyClass. Since MyClass is not a static class, the dance will never begin.
2. so, changing the access modifier to MyClass' ctor to 'public, and creating a new instance of 'MyClass:
a. you have not created any instances of the Item class simply by creating an instance of 'MyClass ... there's nothing inherently wrong with that.
b. the Items collection in _items will be null ... nothing wrong with that.
3. MyClass does have a 'CurrentItem property which will contain null when instances of MyClass are created.
a. but when you access 'CurrentItem, which only implements a 'get: if your internal List<Item> is null: it will create a new Item and return it, but none of that instance of Item Class has its internal fields initialized.
4. the only other means by which I see in your code creates instances of the 'Item class is provided by code you do not show in your question here, via a call to what looks like an extension method on the DataTable Object: _items = _mainDataTable.ConvertToListOfItems<Item>
Since multiple instances of the 'Item class are, obviously going to be created: with the way you have your code structured now, you can only access the Properties of the last created instance of 'Item via the 'CurrentItem property, or by selecting an instance of 'Item in your List<Item> stored in _items.
So to answer your question, specifically, yes, you can execute int id=obj.CurrentItem.Id; as you show, just after you create an instance of 'MyClass (if you change the ctor to 'public), and id will be set to #0, because your invocation of 'CurrentItem caused a new instance of 'Item to be created, and an integer variable will have a default value of #0 when an instance of a class is created.
Big picture: it looks to me like your code needs some strategic re-thinking, about which I can't comment since I don't understand your exact goals here.
As the code is now (once the ctor of 'MyClass is set to public access) I can create an instance of the 'Item class without creating an instance of 'MyClass: do you really want to allow that to happen ?
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
I am totally new to c#, need urgent help to parse this xml. I want to extract all attribute and node values and load it to data tables so that i can load to sql tables later.
<?xml version="1.0" encoding="utf-8"?>
<Response>
<OrganizationTable maxtimestamp="20121009_100244427" moredata="yes">
<Organization preferredid="4295384274" operation="U">
<ActiveDebtInstrumentCount>0</ActiveDebtInstrumentCount>
<ActiveEquityInstrumentCount>0</ActiveEquityInstrumentCount>
<ActiveInstrumentCount>0</ActiveInstrumentCount>
<AdminStatus>Published</AdminStatus>
<BusinessIntelligenceExists>0</BusinessIntelligenceExists>
<CommonName>Government Capital Corp</CommonName>
<CommonNameLanguageID>505062</CommonNameLanguageID>
<DebtInstrumentCount>0</DebtInstrumentCount>
<DocumentsExist>0</DocumentsExist>
<DomiciledInGeographyID>100319</DomiciledInGeographyID>
<EFXId>10823945</EFXId>
<EntityLastReviewedDate>2013-06-28T04:00:00</EntityLastReviewedDate>
<EquityInstrumentCount>0</EquityInstrumentCount>
<FilingsExist>0</FilingsExist>
<GemAlphaNumericID>CT01Z1CZPU</GemAlphaNumericID>
<HasBusinessDescriptionInVFDB>1</HasBusinessDescriptionInVFDB>
<HasDeals>0</HasDeals>
<HasFinancials>0</HasFinancials
><HasFinancialsInVFDB>0</HasFinancialsInVFDB>
<HasIndustryCodeInVFDB>1</HasIndustryCodeInVFDB>
<HasOwnership>0</HasOwnership>
<HasProfileInVFDB>1</HasProfileInVFDB>
<PrefImmediateParentOrganizationID>4295384274</PrefImmediateParentOrganizationID>
<ImmediateParentOrganizationID>4295384274</ImmediateParentOrganizationID>
<IncorporatedInGeographyID>100319</IncorporatedInGeographyID>
<InstrumentCount>0</InstrumentCount>
<IsCapitalMarketsActive>0</IsCapitalMarketsActive>
<IsFundSupportCompany>0</IsFundSupportCompany>
<IsIndexConstituent>0</IsIndexConstituent>
<IsOrganizationManaged>1</IsOrganizationManaged>
<IsOrganizationVerified>1</IsOrganizationVerified>
<IsPublic>0</IsPublic>
<LegalName>GOVERNMENT CAPITAL CORP.</LegalName>
<LegalNameLanguageID>505062</LegalNameLanguageID
><MXID>108985413</MXID>
<NDAOrganizationType>CO</NDAOrganizationType>
<NDAOrgID>107972635</NDAOrgID>
<OfficersDirectorsExist>0</OfficersDirectorsExist>
<OrganizationFoundedDay>6</OrganizationFoundedDay>
<OrganizationFoundedMonth>11</OrganizationFoundedMonth>
<OrganizationFoundedYear>1992</OrganizationFoundedYear>
<OrganizationID>4295384274</OrganizationID>
<OrganizationJurisdictionOfIncorporationTypeCode>477</OrganizationJurisdictionOfIncorporationTypeCode>
<OrganizationNodeType>STANDALONE</OrganizationNodeType>
<OrganizationParentTypeCode>SELF OWNED</OrganizationParentTypeCode>
<OrganizationPI>17768471</OrganizationPI>
<OrganizationProviderTypeCode>1</OrganizationProviderTypeCode>
<OrganizationStatusCode>Act</OrganizationStatusCode>
<OrganizationSubTypeCode>COR</OrganizationSubTypeCode>
<OrganizationTypeCode>COM</OrganizationTypeCode>
<OrganizationWebsite>http://www.govcap.com/about-gcc#!__about-gcc</OrganizationWebsite>
<PEBackedStatus>Never</PEBackedStatus>
<RCPID>600317805</RCPID>
<RegistrationNumber>0124957400</RegistrationNumber>
<RoleToIssueStatus>AC</RoleToIssueStatus>
<SignificantDevelopmentsExist>0</SignificantDevelopmentsExist>
<SubsidiariesCount>0</SubsidiariesCount>
<TaxID>752462160</TaxID>
<TotalScore>13.00</TotalScore>
<TRBCPrimaryIndustryID>4294951354</TRBCPrimaryIndustryID>
<PrefUltimateParentOrganizationID>4295384274</PrefUltimateParentOrganizationID>
<UltimateParentOrganizationID>4295384274</UltimateParentOrganizationID>
</Organization>
</OrganizationTable>
</Response>
|
|
|
|
|
Well Google[^] has many, many working solutions. The very first[^] one looks promising.
|
|
|
|
|
I did go through the google, but it was very confusing for me since I am very new to c#. I am not familiar with linq or xmldocument or....so couldnt exactly makeout which approach to take.
|
|
|
|
|
You actually need to try out some of this stuff for yourself though. If you see a result, look at it and try it out. Then you'll know if it fits your needs or not. And if you're new to C#, you might want to buy some basic books on it.
|
|
|
|
|
I wish I had that much time
|
|
|
|
|
I can't expect to find anyone doing your work for you...
|
|
|
|
|
How much time did you waste waiting for someone here to come along with the answer though? Bear in mind that, as volunteers, we answer questions when we can, so you could have waited hours before you got any answer.
|
|
|
|
|
I did try lot of things before i posted question here. what i meant was I wish i had time to go through the books now.
|
|
|
|
|
Can´t run before you walk.
XML can become pretty complex very soon so time or no time, my advice would be to complete a tutorial (a book, no website) reading, including excercises before diving into this.
C# and XML, I would recommend LINQ (to XML), but before diving into LINQ you need a thorough knowledge of .NET.
|
|
|
|
|
Different approach from Pete's answer is to use XMLSerializer deserialize[^]
Google has many examples that you could work from.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Member 10264177 wrote: I am totally new to c#,
If you are totally new to programming as well then you might want to give up.
If you however experience in the SQL of your database then it is likely you can solve it using only that and much faster than learning enough C# to meet your "urgent" need.
|
|
|
|
|
If you use Linq To XML, you can do 90% of the processing with a single class: XElement. Linq To XML is elegant, and gives you (for example) IEnumerable lists you can process with foreach. It's my first choice for parsing XML.
|
|
|
|
|
I am Making one Window Form in visual studio 2010 using c# in this Form I want To Show Lost of Images and this images come form specific path or From folder
Example:
There is one hospital LeftHead side Patient List On click of PatientName in next panal I want show some related images of this patient so in this case what kind of tool i use to solve this problem
Thank You
Sanket
|
|
|
|
|
The Picturebox I believe.
PictureBox pictureBox1 = new PictureBo();
pictureBox1.Image = System.Drawing.Image.FromFile(@"");
With great code, comes great complexity, so keep it simple stupid...
|
|
|
|
|
Well, to handle the image management and display, I'd use the techniques I wrote about in this[^] article.
|
|
|
|
|
Hi!
I need to be connect to DB2 Database in my Project,it seem'd to be a easy task but i got some problems. I tryed to install IBM Add On for Visual Studio but i cant install it (like it could be only installed on normal visual studio but not on free express) It is a AS400 DB we connect using port 10 to address 192.168.52.10 on local server. I'm a newbie so please write in simple language Thanks Chris
|
|
|
|
|
Chris-Za wrote: I'm a newbie so please write in simple language Well, you haven't really explained what the problem is, apart from implying that you need an IBM addin. However, you may find http://www.connectionstrings.com/[^] a good place to look for some suggestions.
Veni, vidi, abiit domum
|
|
|
|
|
Hi Thanks for reply.
I try'd on the start the default OLEDB driver but cant menage the conn. string.
Got Error Message
base {System.Data.Common.DbException} = {"[DBNETLIB][ConnectionOpen (ParseConnectParams()).]Ungültige Verbindung."} (not guilty connection) ,ErrorCode = -2147467259
The Address and port are ok , vpn connection is fine.
Here are my connection string settings:
1)
string conn_str = @"Provider=SQLOLEDB;Network Transport Library=TCPIP;
Network Address=192.168.52.10:10;Initial Catalog=UDVM400DAT;
User ID=xxx;
Password=xxx;
2) second string
string connw = "Provider=SQLOLEDB;Server=192.168.52.10:10;Database=UDVM400DAT;UID=xxx;PWD=xxx;
Can You figure out whats wrong with the conn string? I had problems on running Toad for DB2, the Razor SQL is working but it use some java driver for AS400. Regards Chris
|
|
|
|
|
|
Chris-Za wrote: I need to be connect to DB2 Database in my Project,it seem'd to be a easy task but i got some problems. I tryed to install IBM Add On for Visual Studio but i cant install it (like it could be only installed on normal visual studio but not on free express) It is a AS400 DB we connect using port 10 to address 192.168.52.10 on local server. I'm a newbie so please write in simple language Visual Studio Express does not support Add Ons.
Still, one would not need a visual studio addon to simply connect to a database; your application will probably have to connect to a database sooner or later, without the help of visual studio or it's addons.
What you'd need is a "Data Provider" for IBM DB2. If none is present, use the OleDbProvider and it's related classes.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace EmployeeAttendanceRegister
{
public partial class SignIN : Form
{
public SignIN()
{
InitializeComponent();
}
public OleDbConnection GetsqlCon()
{
string connstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/game/Desktop/3rd year/2nd Semester/INYM 328/EmployeeAttendanceRegister/EmployeeAttendanceRegister/EmployeeAttendanceRegister.accdb";
OleDbConnection mycon = new OleDbConnection(connstring);
mycon.Open();
return mycon;
}
public void getComm(string connstring1)
{
OleDbConnection sqlcon = this.GetsqlCon();
OleDbCommand sqlcomm = new OleDbCommand(connstring1, sqlcon);
sqlcomm.ExecuteNonQuery();
sqlcomm.Dispose();
sqlcon.Close();
sqlcon.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string col1 = dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col2 = dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col3 = dataGridView1[2, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col4 = dataGridView1[3, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col5 = dataGridView1[4, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col6 = dataGridView1[5, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col7 = dataGridView1[6, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string insert_sql = "INSERT INTO Attendance(Username,Lastname,Firstname,Cellnumber,Officenumber,DepartmentName,Passwrd) VALUES('" + col1 + "','" + col2 + "','" + col3 + "','" + col4 + "','" + col5 + "','" + col6 + "','" + col7 + "')";
this.getComm(insert_sql);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
|
|
|
|
|
First things first. Google for "SQL Injection Attack" to find out why building a SQL query string like you have is such a bad idea. I'll give you two hints: Security and Maintainability.
Then Google for "C# Access Parameterized Query" for what to do about it.
|
|
|
|
|
Alright thank you Dave I will.
|
|
|
|