|
Is this happenning on non-duplicate values, or are you trying to add multiple records with the same value in the primary index field? It isn't clear what's going on...
|
|
|
|
|
I have DataSet and DataGrid,in my application I add or delete some records from DataGrind,after all I check the dataset if anything change compare to the original datasource,if something change or add or delete,it add these change to the datasource.The code made these changes is here:
deletedRows =myDataSet.GetChanges(System.Data.DataRowState.Deleted);
if (((deletedRows) != (null)))
{
myOleDbAdapter.Update(deletedRows,"Companies");
}
updatedRows = myDataSet.GetChanges(System.Data.DataRowState.Modified);
if (((updatedRows) != (null)))
{
myOleDbAdapter.Update(updatedRows,"Companies");
}
insertedRows =myDataSet.GetChanges(System.Data.DataRowState.Added);
if (((insertedRows) != (null)))
{
myOleDbAdapter.Update(insertedRows,"Companies");
}
Roger Wright wrote:
Is this happenning on non-duplicate values, or are you trying to add multiple records with the same value in the primary index field?
I don't know when I add non-duplicate or duplicate,I mean I don't what are they to know when I add which of them.The error tell me that I create multiple value in the index,primary key or relationship.This happend the SECOND time I call that function not for the first time.
Thanks
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I've read your thread with Roger and I'll try taking a scond approach at explaining the problem.
In a database you have tables; each table has one or more Primary Keys defined on it. A primary key is made up of one or more fields.
A primary key is a unique value in the table, there can only be one such key in the table as well. If you only have one field, called username then each username in the table must be unique. Now you can also have two fields be the primary key; in that case that same combination of values can only exist in the table once. If you have a primary key made up of UserID and OrderID then you can have multiple records with the same UserID and you can have multiple records with the same OrderID, but you can have only one record with the same combination of UserID AND OrderID.
The error you are receiving is because you are trying to add (or update) a record that would create a duplicate primary key.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Smile your little smile, take some tea with me awhile.
And every day we'll turn another page.
Behind our glass we'll sit and look at our ever-open book,
One brown mouse sitting in a cage."
"One Brown Mouse" from Heavy Horses, Jethro Tull 1978
|
|
|
|
|
hmmmmm,now I got the point .
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Seems that using a parameterized query as a SelectCommand for an OleDbDDataAdapter to fill a DataSet doesn't work!
The following code is how I'm doing that. All the code is inside an try/catch block. The language i'm using is C#
// Using a UDL file for the connection string
string strDBConn = "FileName=D:\Contacts.udl;";
// Sets up the connection
OleDbConnection conn = new OleDbConnection(strDBConn);
conn.Open(strDBConn);
// Creates a new command
OleDbCommand cmd = new OleDbCommand(
"select * from dbo.Contacts where contact_id = ?", conn);
// Sets up the Data Adapter
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
// Sets the Command parameters
param = da.SelectCommand.Parameters.Add (
"@contact_id", OleDbType.Numeric, 9, "entid_id");
param.Value = 1; // The parameter value
// creates a new DataSet
DataSet dsResult = new DataSet()
// Fills the DataSet
da.Fill(dsResult);
Somehow in the last instruction it generates an exception that even 'catch (Exception e)' can't get exactly because in spite of falling in this catch block the 'e' (the exception) is null!
But the reason he is throwing some weird exception is because the parameters are not being declared first before querying the database with the parameterized select command and consequently the string that is being sent is only "select * from dbo.Contacts where contact_id = @P1" and nothing else.
I'm using a .UDL file to set my connection string which is set with valid parameters because it's being used everywhere else in the app and it works perfectly.
My Database is SQL Server 2000... Yeah, of course I could use SqlDataAdapter and all the other classes specific for SQL Server but the fact is that I want to use an .UDL file to set my datasource and the only way to do this is using the OleDb... classes. UDL files doesn't work with SqlConnection in case you didn't know.
So... am I doing something wrong here in setting the Data Adapter to a parameterized query? Is this a bug in the .NET framework? Can you help me out with this? Thanks in advance
Best Regards,
Paulo
|
|
|
|
|
I am having a problem with a server side component (DLL) i am developing for an ASP page.
Im not really sure what the problem is. I tested the code in a vbproject and it worked perfectly but
when I try it in an ASP page, it doesnt work.
**************************************************************
My ASP page looks like this
<%@ Language=VBScript %>
<%
dim obj
set obj = server.CreateObject("Danny.Lopez")
Response.Write(obj.GetTeam(1))
%>
***************************************************************
This is the error im getting
Error Type:
Danny (0x800A01A8)
Object required
/Project1/Registration.asp, line 10
***************************************************************
This is some of the the code in my ActiveX DLL
Public Function GetTeam(TeamID As Integer) As String
Dim sql As String
sql = "SELECT Name FROM Teams WHERE TeamID = " & TeamID
GetTeam = ExecuteQuery(sql, True)(0)
End Function
Private Function ExecuteQuery(sql As String, Optional CloseConnection As Boolean = False) As ADODB.Recordset
Dim state As Integer
state = DataEnvironment1.Connection1.state
If state = 0 Then
DataEnvironment1.Connection1.Open
End If
Dim rs As ADODB.Recordset
Set rs = DataEnvironment1.Connection1.Execute(sql)
Set ExecuteQuery = rs
If state = 0 And Not CloseConnection Then
DataEnvironment1.Connection1.Close
End If
End Function
***************************************************************
To make sure the DLL worked at all in the ASP page I created a simple function that takes a
string and returns it.
Public Function Repeat(str As String) As String
Repeat = str
End Function
This function worked in an ASP pef
***************************************************************
I feel the error has to do with the data types im passing to my DLL, but im not sure.
Please Help!!!!
Thanks Danny
|
|
|
|
|
DanielLopez wrote:
Public Function GetTeam(TeamID As Integer) As String
Dim sql As String
sql = "SELECT Name FROM Teams WHERE TeamID = " & TeamID
GetTeam = ExecuteQuery(sql, True)(0)
End Function
Rewrite the above function as ...
Public Function GetTeam(TeamID As Integer) As String
Dim sql As String
Dim rs as ADODB.Recordset
sql = "SELECT Name FROM Teams WHERE TeamID = " & TeamID
set rs = ExecuteQuery(sql, True)
GetTeam = rs.Fields(0)
End Function
Grant @ Loki
|
|
|
|
|
I have a datagrid and its connected to database ,I use this funcion to save changes to
datasource from datagrid:
private void btnSave_Click(object sender, System.EventArgs e)
{
deletedRows=null;
updatedRows=null;
insertedRows=null;
try
{
deletedRows =myDataSet.GetChanges(System.Data.DataRowState.Deleted);
if (((deletedRows) != (null)))
{
myOleDbAdapter.Update(deletedRows,"Companies");
}
updatedRows = myDataSet.GetChanges(System.Data.DataRowState.Modified);
if (((updatedRows) != (null)))
{
myOleDbAdapter.Update(updatedRows,"Companies");
}
insertedRows =myDataSet.GetChanges(System.Data.DataRowState.Added);
if (((insertedRows) != (null)))
{
myOleDbAdapter.Update(insertedRows,"Companies");
}
myDataGrid.ReadOnly=true;
}
catch(Exception myE)
{
MessageBox.Show("Problem!!" + myE.ToString());
}
}
For the first time it works ok but second time I unhandle error thrown:
---------------------------
---------------------------
System.Data.OleDb.OleDbException: The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
at WindowsApplication3.Form1.btnSave_Click(Object sender, EventArgs e) in f:\visual studio projects\projectc#\windowsapplication3\form1.cs:line 219
---------------------------
OK
---------------------------
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I want to check if my connection is close or not but Close() does not return any value.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Do you mean, check if Close() has REALLY closed the connection, or check at any given time if a particular connection object is open ?
in the latter, what about setting the connection object to null after calling Close(), and then check if the object is null when you are about to use it ?
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Andres Manggini wrote:
Do you mean, check if Close() has REALLY closed the connection, or check at any given time if a particular connection object is open ?
No,I want to open it if I close it in another places in my program.
Andres Manggini wrote:
in the latter, what about setting the connection object to null after calling Close(), and then check if the object is null when you are about to use it ?
This is good idea.
I looked into MDSN and found ConnectionState ,but I couldn't find out how to work with it,the example in MSDN is not good one,like always;)
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Yeah, that work too..
That property can take to values:
The allowed state changes are:
Property Value
A bitwise combination of the ConnectionState values. The default is Closed.
From Closed to Open, using the Open method of the connnection object.
From Open to Closed, using either the Close method or the Dispose method of the connection object.
[C#]
public void createOleDbConnection()
{
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;";
myConnection.Open();
MessageBox.Show("Connection State: " + myConnection.State.ToString());
myConnection.Close();
}
this helps ?
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Andres Manggini wrote:
public void createOleDbConnection()
{
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;";
myConnection.Open();
MessageBox.Show("Connection State: " + myConnection.State.ToString());
myConnection.Close();
}
This is the one MSDN,and I said I see this before,the problem is that how to check the condition state not convert to string.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I think you're looking for the System.Data.ConnectionState enum.
Andy Gaskell, MCSD MCDBA
|
|
|
|
|
AndyG wrote:
I think you're looking for the System.Data.ConnectionState enum.
Yes,If you read all the thread you figure out that the problem is that I need an example for that.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Sure....
OleDbConnection thisIsNotRocketScience = new OleDbConnection();
if(thisIsNotRocketScience.State == System.Data.ConnectionState.Closed)
WriteTehL33tC0des();
else
WriteEv3nl33t3rC0dez();
Andy Gaskell, MCSD MCDBA
|
|
|
|
|
Thanks Andy,
AndyG wrote:
WriteTehL33tC0des();
I could not find it in MSDN,Is that somrthing in your codes?
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I have been reading up on the various ways of installing the actual database on client's SQL servers.
What methods are you using? What did you consider to be the best way?
Michael
|
|
|
|
|
You are talking about your Database or the Server?
Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
Installing the database (its tables, stored procedures) onto an already existing SQL Server 2000.
Michael
|
|
|
|
|
Michael:
I always prepare a SQL Script, with the creation of the Tables, Stored Procedures, Views, Groups, minimal Users if is necessary, Permits by Group, etc....
Then I prepeare another script with the initial data if that is required.
And Ready...
I work for A Very Important Bank in the World, when I need to implement a new Application we make That, because I have no Access to Production, And those Scripts are run by the operators of the data center...
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
Thats the method I'm thinking of using. I was just interested to know how everybody else does it. First time I've deployed an SQL server app since the days of SQL Server 6.5.
Michael
|
|
|
|
|
Yes is the more common method... I travel for all the world and I know that the developer use the scripts to implment the SQL Databases....
I make that from SQL Server 4.0 or 4.2 I don't remember the version..
Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
hi all,
I want to using .cdb file in the PocketPC.(ADO using in the Windows CE 3.0). if anyone know please send samples me..
thanks .
MFC
|
|
|
|
|
I am working on a small application server for updating customer orders. Multiple clients (in sales department) can be connected to the server do create orders, and browse the orders.
I used conventional TCP/IP way to send data back to client. I created a ADO Recordset in my application, and pass the first 50 rows to the client, so the client can navigate the rows. However, when it beyongs the first 50, i have to do MoveNext() in the server. I doubt that my manipulation will fail in maintaining a row_no in the client where the client navigated up to. Can someone tell me a better way to handle the client side cache issue, and make it *current *position synchronized with the application server's Ado Recordset position.
By the way, I'm using VC++ 6.0 , SP5. Oracle 8i
|
|
|
|
|