D
Darryn Ross
Hi,
I am having difficulty updating an existing record in a database through an
untyped dataset. Can't seem to work out what i am doing wrong, and have had
no luck finding any good examples on the net that match what i want to do.
Below is my code segment, currently i am getting an error that states
"Column 'Code' contains non-unique values" and i don't understand why it's
giving it to me, because there is only one record with that code and its the
one i am trying to update.
Any help would be appreciated.
DataRow tblRow ;
DataColumn[] pki = new DataColumn[1] ;
try {
DtlsConnection.ConnectionString = ConnectionPath ;
DtlsConnection.Open() ;
DtlsCommand.CommandText = "Select * From tbl" ;
DtlsCommand.Connection = DtlsConnection ;
DtlsAdapter.SelectCommand = DtlsCommand ;
DtlsAdapter.Fill(DtlsDs, "tbl") ;
pki[0] = SecurityDtlsDs.Tables["tbl"].Columns["Code"] ;
pki[0].Unique = true ;
DtlsDs.Tables["tbl"].PrimaryKey = pki ;
tblRow = DtlsDs.Tables["tbl"].Rows.Find(pCode) ;
tblRow.BeginEdit() ;
tblRow["Code"] = txtCode.Text ;
tblRow["Name"] = txtName.Text ;
tblRow["Type"] = txtType.Text ;
tblRow.EndEdit() ;
DtlsAdapter.Update(DtlsDs, "tbl") ;
//DtlsAdapter.Fill(DtlsDs, "tbl") ;
}
catch (Exception e) {
MessageBox.Show(e.Message, "Finwin", MessageBoxButtons.OK,
MessageBoxIcon.Error) ;
}
//Closing the connection
DtlsConnection.Close() ;
Kind Regards
Darryn Ross
I am having difficulty updating an existing record in a database through an
untyped dataset. Can't seem to work out what i am doing wrong, and have had
no luck finding any good examples on the net that match what i want to do.
Below is my code segment, currently i am getting an error that states
"Column 'Code' contains non-unique values" and i don't understand why it's
giving it to me, because there is only one record with that code and its the
one i am trying to update.
Any help would be appreciated.
DataRow tblRow ;
DataColumn[] pki = new DataColumn[1] ;
try {
DtlsConnection.ConnectionString = ConnectionPath ;
DtlsConnection.Open() ;
DtlsCommand.CommandText = "Select * From tbl" ;
DtlsCommand.Connection = DtlsConnection ;
DtlsAdapter.SelectCommand = DtlsCommand ;
DtlsAdapter.Fill(DtlsDs, "tbl") ;
pki[0] = SecurityDtlsDs.Tables["tbl"].Columns["Code"] ;
pki[0].Unique = true ;
DtlsDs.Tables["tbl"].PrimaryKey = pki ;
tblRow = DtlsDs.Tables["tbl"].Rows.Find(pCode) ;
tblRow.BeginEdit() ;
tblRow["Code"] = txtCode.Text ;
tblRow["Name"] = txtName.Text ;
tblRow["Type"] = txtType.Text ;
tblRow.EndEdit() ;
DtlsAdapter.Update(DtlsDs, "tbl") ;
//DtlsAdapter.Fill(DtlsDs, "tbl") ;
}
catch (Exception e) {
MessageBox.Show(e.Message, "Finwin", MessageBoxButtons.OK,
MessageBoxIcon.Error) ;
}
//Closing the connection
DtlsConnection.Close() ;
Kind Regards
Darryn Ross