Hello Steven C.,
Instead of Console.WriteLine use Debug.WriteLine and see in VD IDE output
window whether your datatable has primary key
S> Hi Michael:
S>
S> Thanks for replying. Here's the XML. Sorry about the formatting.
S>
S> I tried the code that you suggested. I'm kind of a newbie in C#, so
S> forgive me, but, where is that console.writeline output supposed to
S> go? I'm in the .NET IDE, and I don't see it in any of the panes. Do
S> I have to explicitly turn this feature on somewhere?
S>
S> Thanks!
S> Steven
S> <?xml version="1.0" encoding="utf-8" ?>
S> <xs:schema id="MortgagesDS"
S> targetNamespace="http://tempuri.org/MortgagesDS.xsd"
S> elementFormDefault="qualified"
S> attributeFormDefault="qualified"
S> xmlns="http://tempuri.org/MortgagesDS.xsd"
S> xmlns:mstns="http://tempuri.org/MortgagesDS.xsd"
S> xmlns:xs="http://www.w3.org/2001/XMLSchema"
S> xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
S> <xs:element name="MortgagesDS" msdata:IsDataSet="true">
S> <xs:complexType>
S> <xs:choice maxOccurs="unbounded">
S> <xs:element name="Table">
S> <xs:complexType>
S> <xs:sequence>
S> <xs:element
S> name="nMortgage_pk" type="xs:int" minOccurs="0"
S> msdata:AutoIncrement="true" msdata:AutoIncrementSeed="-1"
S>
S> msdata:AutoIncrementStep="-1" />
S> <xs:element
S> name="cLenderName" type="xs:string" minOccurs="0" />
S> <xs:element
S> name="cLoanId" type="xs:string" minOccurs="0" />
S> <xs:element
S> name="nLoanAmount" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nInterestRate" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nSquareFeet" type="xs:double" />
S> <xs:element
S> name="nLoanYears" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nClosingCost" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nSchoolPropTax" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nPrincipleInterest" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nTotalTaxes" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nCostPerSqFoot" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nMonthlyPayment" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="cAddress1" type="xs:string" minOccurs="0" />
S> <xs:element
S> name="cAddress2" type="xs:string" minOccurs="0" />
S> <xs:element
S> name="cCity" type="xs:string" minOccurs="0" />
S> <xs:element
S> name="cState" type="xs:string" minOccurs="0" />
S> <xs:element
S> name="cZip" type="xs:string" minOccurs="0" />
S> <xs:element
S> name="nTotalInterest" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nHouseCost" type="xs:double" minOccurs="0" />
S> <xs:element
S> name="nDownPayment" type="xs:double" minOccurs="0" />
S> </xs:sequence>
S> </xs:complexType>
S> </xs:element>
S> </xs:choice>
S> </xs:complexType>
S> <xs:key name="nMortgage_pk">
S> <xs:selector xpath=".//mstns:Table" />
S> <xs:field xpath="mstns:nMortgage_pk" />
S> </xs:key>
S> </xs:element>
S> </xs:schema>
S> On Sat, 4 Mar 2006 20:19:26 +0000 (UTC), Michael Nemtsev
S> <ne*****@msn.com> wrote:
S>
Hello Steven C.,
Could you show XSD? Seems that smth wrong with it. Try to call code
below to see if PrimaryKey exist in DataTable
private void GetPrimaryKeys(DataTable table)
{
// Create the array for the columns.
DataColumn[] columns;
columns = table.PrimaryKey;
// Get the number of elements in the array.
Console.WriteLine("Column Count: " + columns.Length);
for(int i = 0; i < columns.Length; i++)
{
Console.WriteLine(columns[i].ColumnName + columns[i].DataType);
}
}
S> Hello:
S>
S> I'm getting an error, "primary key not defined" when trying to use
S> the FIND method on the DataTable Rows collection.
S>
S> I have a typed dataset called 'MortgagesDS' that I created with
the
S> XSL builder tool in .NET. I define the dataset at the beginning
the
S> the main class:
S>
S> MortgageDS _MortgageDS = new MortgageDS();
S>
S> And then I do a data pull from an Access database (with primary
key
S> defined) into a table called 'tblMortgages' from within a method
S> inside the class.
S>
S> strSql = "SELECT * FROM tblMortgages";
S> OleDbConnection conn = this.m_GetAccessConnection();
S> OleDbDataAdapter da = new OleDbDataAdapter(strSql,conn);
S> da.Fill(_MortgagesDS,"tblMortgages");
S> Later in the code, I try to locate a record from the tblMortgages
S> table using the FIND method:
S>
S> DataRow foundrow;
S> foundrow =_MortgagesDS._Table.Rows.Find(intMortgagePk);
S> if(foundrow == null)
S> Console.WriteLine("No Row Found");
S> else
S> {
S> this.tbLenderName.Text = foundrow[1].ToString();
S> }
S> However, I get an error, Primary Key Not Defined when I try to
locate
S> the row. The XSL definition has the primary key defined, and the
S> Access database has the same field defined as the primary key, so
S> what am I doing wrong? I'm using Visual Studio 2003.
S>
S> Many thanks!
S>
S> Steven
S>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog:
http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche