|
I'm trying to update an access database via the update method from a modified dataset.
I know the dataset is modified, and the DataAdapter is valid and functional.
I fill my dataset with this command in the data adapter:
"SELECT [File Extentions].*
FROM [File Extentions]"
Then, i add a number of rows via this method:
private bool Add(string extention, Type castType)<br />
{<br />
DataTable currentTable = ds_Data.Tables["Table"];<br />
<br />
DataRow newRow = currentTable.NewRow();<br />
<br />
newRow["File_Extention"] = extention;<br />
newRow["File_Type"] = castType;<br />
<br />
currentTable.Rows.Add(newRow);<br />
<br />
ds_Data.AcceptChanges();<br />
<br />
adapter.Update(currentTable);<br />
<br />
return true;<br />
}
The changes are reflected in the data adapter, but not in the database.
Does anyone know why this is?
Cheers
Cata
|
|
|
|
|
I think it is because you are calling ds_Data.AcceptChanges().
It commits all the changes made to your dataset which means the DataRowState for all rows are changed from Added to Unchanged. Therefore, your adapter.Update(currentTable) won't update your database as the data in the table is considered original/unchanged.
Just remove the ds_Data.AcceptChanges() as the adapter.Update() will automatically call this for you. As long as you set the right InsertCommand your database should be updated.
Edbert P.
Sydney, Australia.
|
|
|
|
|
[EDIT]:
Sorry, found out why it was spitting it out. Didn't like spaces in the table name. My mistake, thanks for the help.
[EDIT]
If i don't use AcceptChanges, it throws an OLEDBException when i try to run the update method.
Any other ideas?
I'm pretty new to DB programming, just trying to get all the n00b stuff under my belt.
Cata
|
|
|
|
|
In trying to create a recordset I keep getting an error when I open it under C#. I would use ADO.NET, but for backwards compliance with the application it talks too, I need ADO 2.6. Below is a snippet of the code I am using. If anyone has input as to what the problem may be, please let me know.
[code]
ADODB.Recordset rs = new ADODB.Recordset;
Object obj1 = null;
Object obj2 = null;
rs.Fields.Append( "Name", adVarChar, 32, adFldMayBeNull, null );
rs.CursorLocation = adUseClient;
rs.Open( obj1, obj2, adOpenForwardOnly, adLockReadOnly, -1 );
[/code]
This code causes a COMException under C# that says: "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another." The same code works fine under regular c++ and VB6. Does anyone have any input to this?
|
|
|
|
|
If you need to omit an optional parameter in a COM call using C#, you should use System.Reflection.Missing.Value .
ADODB.Recordset rs = new ADODB.Recordset();
rs.Fields.Append(
"Name",
DataTypeEnum.adVarChar,
32,
FieldAttributeEnum.adFldMayBeNull,
null );
rs.CursorLocation = CursorLocationEnum.adUseClient;
rs.Open(
Missing.Value,
Missing.Value,
CursorTypeEnum.adOpenForwardOnly,
LockTypeEnum.adLockReadOnly,
-1 );
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thank you very much. I am still learning the intricisies of C# and haven't looked into the System.Reflection namespace much yet. Everything works fine now. Thanks for the help.
|
|
|
|
|
just one small question
in my prog i have an i_data value from listctrl and i want to move in recorset
to record with the same ID member, so i'm doing this:
pDoc->m_fmediaMDBSet.MoveFirst();
while (!pDoc->m_fmediaMDBSet.IsEOF()) {
if (pDoc->m_fmediaMDBSet.m_ID == i_data)
break;
pDoc->m_fmediaMDBSet.MoveNext();
}
ASSERT(pDoc->m_fmediaMDBSet.m_ID == i_data);
...
and i don't like it
is there a better (and faster) way to do this job?
thanks again
Chris
|
|
|
|
|
(Beep) not enough information to proceed (Beep)
My solution to such a problem:
I keep the recordset and the list-control in sync, so that the index of the list-element is the same as the one in the recordset, ie
int nIndex;
if( -1 ==( nIndex =GetListCtrl().GetNextItem( -1, LVNI_SELECTED )))
{
return;
}
m_pSet->SetPosition( nIndex+1 );
hope it will help ,
dirk
|
|
|
|
|
yess (: it is what i was looking for
I was using old mfc4.1.hlp documentation and there is nothing about
CRecordset::SetAbsolutePosition(..)
thanks
Chris
|
|
|
|
|
Hi
I need a free SQL Server 2000 E-Book
Who can help me
i fpund one but it was in chinees language..
|
|
|
|
|
|
Thanks
I was born intelligent Education ruined me!.
|
|
|
|
|
I want to create a Stored procedure that looks up data based off the last full month and also one for year to date data. These SP will fire as part as a script so there can be no user input regarding the dates. Is there a way to do this?
Chris
|
|
|
|
|
Sure.
Just put a condition like below for data from the last month
WHERE MONTH(dtmTransactionDate) = MONTH(DATEADD(m, -1, GETDATE()))<br />
AND YEAR(dtmTransactionDate) = YEAR(DATEADD(m, -1, GETDATE()))
If you need to get specific date (e.g. starting from 15 of Jan to 15 of Feb) just add DAY condition to it.
For year to date, just subtract 1 year from the current date using the DATEADD function.
Edbert P.
Sydney, Australia.
|
|
|
|
|
If you are interested in the last full month and need the last day - you run into problems with February.
Try:
declare @month char(10),@lastmonth datetime
set @month = Convert(Char(6),getdate(),112)+'01'
Print @month
select @lastmonth = dateadd(m,-1,cast(@month as datetime))
print @lastmonth --First day of prior month
select @lastmonth = dateadd(d,-1,cast(@month as datetime))
print @lastmonth --Last day of prior month
Barbara
|
|
|
|
|
create table TestLoan(
loanid int identity(1,1),
custid int,
loanvalue varchar(50)
)
GO
INSERT INTO TestLoan values(2,'First Loan')
INSERT INTO TestLoan values(2,'Second Loan')
INSERT INTO TestLoan values(2,'Third Loan')
INSERT INTO TestLoan values(2,'Fourth Loan')
INSERT INTO TestLoan values(2,'Fifth Loan')
GO
Does anyone know a way I could return the 3 most recent loans in the same row? The trick would be making it always be the 3 most recent loans, no matter what else was added.
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
Here is one that you might be able to use:
DECLARE @TotalLoanValue varchar(150)<br />
<br />
SELECT TOP 3 @TotalLoanValue = COALESCE(@TotalLoanValue + ', ', '') + loanvalue<br />
FROM TestLoan<br />
ORDER BY loanid DESC<br />
<br />
SELECT @TotalLoanValue
This will work with SQL 2K. I haven't tested it with any other DBs.
It will return something like this:
Fifth Loan, Fourth Loan, Third Loan
I hope this helps
Edbert P.
Sydney, Australia.
|
|
|
|
|
Wow Edbert - I'm not even sure how this works. Isn't COALESCE meant to return the first non null value? Can you explain the mechanics a bit?
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
Sorry, it was 9AM in the morning and I haven't had my coffee
Yes, COALESCE is meant to return the first non-null value from the values passed.
Have a look at this code:
SELECT TOP 3 @TotalLoanValue = COALESCE(@TotalLoanValue + ', ', '') + loanvalue
The first time the @TotalLoanValue variable is processed, it will return NULL as the value. I use COALESCE to return empty string ('') instead, so when I concatenate the next rows, they will not result in null.
You can also use ISNULL(@TotalLoanValue + ', ', '') instead of COALESCE(@TotalLoanValue + ', ', '') as they're basically doing the same thing, except that ISNULL only accepts two values.
What the whole SQL statement does is just to concatenate the result of the query into one comma-delimited string. Just change the delimiter if you need to.
Good luck!
PS: Use WHERE loanvalue IS NOT NULL if you want to always return 3 records.
Edbert P.
Sydney, Australia.
|
|
|
|
|
Self joins! There are a beautiful thing when some Neanderthal wants a denormalized report from you nice orderly normalized data structure.
Try this (works on sql server. Access is ???):
select top 1 *
from
testloan t1,
testloan t2,
testloan t3
where
t1.loanid<>t2.loanid and
t2.loanid<>t3.loanid and
t1.loanid<>t3.loanid
order by
t1.loanid desc,
t2.loanid desc,
t3.loanid desc
Bill
|
|
|
|
|
I'm a little confused. How do I know what's being returned to me from a stored procdure when I call it from my C++ app?
For instance I want to write a program that returns back all users accessing a database. I found the stored procedure called "sp_who". I think I understand how to call it but I'm unsure how I find out what is returned to me. Is there not a way to do this on the fly in the code?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
SELECT loginame, hostname FROM Master.dbo.sysprocesses
WHERE loginame != 'sa'
this should give you all the users loged on the server
Will
|
|
|
|
|
I am preparing to migrate a legacy system using foxpro tables (.dbfs) to VB.NET. During the transition stage, some of the new system needs to access data inside foxpro tables. I am now coding the data access component to handle these tasks. My initial code testing revealed, that the time to transfer records from foxpro tables to a ADO.NET's dataset table took a lot of time.
I am connected with a pre-need company (similar to insurance) so we basically keep track of planholders and their premium payments (montly, quarterly, semi-annual, annual. payment term is up to 10 years)
The code is the basic dataset creation and fill. The SQL statement is "SELECT * FROM premiumpayments WHERE account = planholderaccountnumber". My test data reads 84 records representing 7 years of monthly preimiun. It took 3-5 seconds to complete from my local drive.
I searched the archive but did not found any related postings. Is there a way to speed up this process? I would really appreciate any help. Thanks!
|
|
|
|
|
I learn the follow commands to backup and restore of SQL Server:
backup database northwind to disk = 'c:\northwind.bak'
restore database northwind from disk = 'c:\northwind.bak'
Ok, but my database is in server of my ISP... How I do to perform backups and restores? I need contact them?
And how I do to download the backups???
Thanks for all by the help.
|
|
|
|
|
I suggest contacting them. Remember that the path you specify in the BACKUP DATABASE command is relative to the database server machine, i.e. the above command will backup to the root of the server's c: drive.
If you don't specify a path, the backups will go to the server's default backup directory.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|