|
parshu21 wrote:
Try not using Keywords for Table/Column names (like Order).
That's good advice - It can get confusing.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
Hi,
I am having trouble adding new rows to an empty MS Access table.
I manually created the table in MS access named server and created two
columns Date & Time.
When I run the following code I get: "Syntax error in INSERT INTO
statement".
Any help would be great.
Thank you.
OleDbCommand fgSelectCommand = conn.CreateCommand();
fgSelectCommand.CommandText = "SELECT TOP 1 * FROM Server";
OleDbDataAdapter fgADOAdapter = new OleDbDataAdapter();
OleDbCommandBuilder fgCommandBuilder = new
OleDbCommandBuilder(fgADOAdapter);
fgADOAdapter.SelectCommand = fgSelectCommand;
DataTable fgDataTable = new DataTable("Server");
fgADOAdapter.FillSchema(fgDataTable, SchemaType.Source);
DataRow fgDataRow = fgDataTable.NewRow();
fgDataRow["Date"] = logWeb.LogDate;
fgDataRow["Time"] = logWeb.LogTime;
fgDataTable.Rows.Add(fgDataRow);
fgADOAdapter.Update(fgDataTable);
|
|
|
|
|
Try ExecuteScaler with a stored procedure and return a Success or Failure value.
Using a stored procedure would be better but here is some SQL to get you started.
This is obvious with VB.Net.
Dim cmd as New SqlCommand
cmd.Connection = cn 'Connection
cmd.CommandText = "Insert into [Server] ([Date], [Time]) Values (yourDate, yourTime)"
cmd.commandType = CommandText
return cmd.ExecuteNonQuery
Hope this helps,
Michael
I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious.
Vince Lombardi (1913-1970)
|
|
|
|
|
Michael,
Thank you for the advice.
Cheers,
Craig
|
|
|
|
|
hi,
the message in debug show "Run-Time Check Failure #2 - Stack around the variable 'ls_BureauID' was corrupted!"
what's the meaning?
thanks!
|
|
|
|
|
Is this field ref'd by a constraint ?
This could be part of the issue.
Tony
|
|
|
|
|
the field is defined as char ls_BureauID[4],now this problem has been resolved by enlarging it's length,but i want to know some more run time knowledge,for when and why this prompt come out?
thanks!
|
|
|
|
|
Sounds more like a C++ issue than a SQL, ADO or ADO.NET issue, unless SQL Server itself is giving this error. Your C++ code is probably overrunning a stack-based buffer.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hello,
I have a question about querying an Access database from a .Net program. I am using C#.
What I want to be able to do is use the instrrev() function in an sql query to find the first period from the right of a string (to get the extension from and e-mail address). However, anytime i try to use instrrev I get an error saying that instrrev is an unknown function. I don't get this error when I use instr(). I researched on the internet and decided that this must be caused by the sandbox mode in the jet engine, so I turned sandbox mode off in Access. However, I still the get the same error when running the query from my C# program. Does anyone know how I can use this function, or is there any other way to solve my problem? I thought about using strreverse() and the using instr(), but it turns out that strreverse() is another function that won't work.
Any help is appreciated. Thanks!
Blake
|
|
|
|
|
Well if all else fails you could just write your own function to find the first instance of a period from the end of the string. This isn't C#, but should give you an idea.
int FindCharRev (const CString str, const char c, CString& buf)
{
char* pStr;
int index, j = 0, len = str.GetLength ();
for (int i = len; i > 0; i--) {
if (str[i] == c)
{ index = i; break; }
}
pStr = (LPTSTR)(LPCTSTR)str;
pStr += index;
while (pStr) {
buf[j] = *pStr;
pStr++;
j++;
}
return index
} That's a crude implementation, but it should put the string after the first instance (from the end of the string) of a character in the "buf" parameter and return the index of where that character was found.
- Aaron
|
|
|
|
|
It sounds like you're trying to get your database to do too much work. If this is in the presentation part of the SELECT, not in any selection clauses (WHERE, HAVING, ON), do it in the C# code once you've got the results.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
My Oracle docs on INSTR say that you pass a negative value for the third parameter, and the search will be done from the end of the string.
select instr('CORPORATE FLOOR,'OR',-3,2) from dual
will a return a value of 2
Not sure if this is the same in access, though.
Chris Meech
We're more like a hobbiest in a Home Depot drooling at all the shiny power tools, rather than a craftsman that makes the chair to an exacting level of comfort by measuring the customer's butt. Marc Clifton
VB is like a toolbox, in the hands of a craftsman, you can end up with some amazing stuff, but without the skills to use it right you end up with Homer Simpson's attempt at building a barbeque or his attempt at a Spice rack. Michael P. Butler
|
|
|
|
|
Anybody worked on this new Reporting Services[^] from Microsoft?
I appreciate your input.
Promise only what you can do. And then deliver more than what you promised. This signature was created by "Code Project Quoter".
|
|
|
|
|
Hi everyone
I'm working a program that needs to interface with a dBase 3 and pull records (sometimes limited amount) based on a zip code field.
Also i need to pull the oldest records first by using MAILED field.
I came up with this query to pull the data:
SELECT TOP 5 * INTO DESTINATON.dbf FROM SOURCE.dbf WHERE ZIP5 = '95003' ORDER BY MAILED ASC
This query works. It select top 5 record, creates DESTINATON.dbf witch is identical in structure to SOURCE.dbf and populates it with selected records.
The hard part is to update the MAILED field in the same query, so next time I don't use the same records.
There in no unique field that i can use to match pulled records to the SOURCE.dbf and update it.
I want to do it all in one shot, but I'm not sure that this is possible.
I'm using ADO 2.7
Any help is greatly appreciated.
Thank you
Ilya
|
|
|
|
|
Try this with your appropriate primary key field name substitution. Not sure about your dbf suffix as it's been about 8 years since I touched dbase.
SELECT TOP 5 SOURCE.*
INTO DESTINATON
FROM SOURCE
LEFT JOIN DESTINATON
on DESTINATON.PRIMARYKEY = SOURCE.PRIMARYKEY
WHERE SOURCE.ZIP5 = '95003'
AND DESTINATON.PRIMARYKEY IS NULL
ORDER BY SOURCE.MAILED ASC
Janya
|
|
|
|
|
Hello people,
I just wanted to know if there's anyone out there who can help me or have done this sort of thing before. I'm using remote data access (i know i could've used data adapters, but i just thought it would be interesting to test out RDA capabilities using .NET Framework). I've managed to create a connection, pulled the data, modify it, and then pushed it back onto the SQL Server 200 from my PDA Sql Server CE. The thing is, the column values pulled from the SQL server is different from my Sql Server CE when i view it in my PDA emulator. The two columns appear after my primary key column, with the column values to be:
s_Binary Key (Column 2) and s_Operation (Column 3)
Is it because of the RDA Tracker? Or is it something in built to SQL Ce? And if there any way i can utilise these columns (if they have any benefits at all)? Please help, cos i can't afford anger management classes anymore...
|
|
|
|
|
the problem of @@TRANCOUNT--how to eliminate the no.266 error
|
|
|
|
|
Ensure that every use of BEGIN TRAN is matched with either a ROLLBACK TRAN or a COMMIT TRAN , regardless of whether an error occurs. In the case of a fatal error, SQL Server will roll back any transactions before it closes your connection.
If you have implicit transactions enabled (through SET IMPLICIT_TRANSACTIONS ON ) a BEGIN TRAN happens automatically the first time you perform any data modification operation. You still have to commit or roll-back this implicit transaction explicitly.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Is there anyway to have the date format set permanently for a database? I think SET DATEFORMAT only sets it for the current session. If there's no way to set it permanently does anyone know how to execute a SET DATEFORMAT using ADO? I'm using the following ADO Wrapper Class[^]. I've tried the Execute function of the database object, but it isn't working. Any ideas would be appreciated. Thanks.
- Aaron
|
|
|
|
|
The default value depends on the client program's locale, IIRC.
This option only applies to how date literals are interpreted by the parser; to ensure that date literals are interpreted correctly, whatever locale is in use, you should supply them in ISO format:
yyyymmdd, e.g. today is '20040413' .
For dates supplied by a user, use the parameter features of ADO (i.e. use CADOCommand::AddParameter with the type CADORecordset::typeDate and use COleDateTime or similar to prepare the value).
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
First, thanks for the reply Mike. Second, I'm now taking your advice and I'm trying to enter an ISO format date, but everytime I try to set the field value I'm getting a _com_error thrown. The error is being thrown by the put_Value function in the msado15.tli file:
inline void Field20::PutValue ( const _variant_t & pvar ) {
HRESULT _hr = put_Value(pvar); <-- Error returned from put_Value
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this)); <-- exeception thrown here
} The debugger is telling me that it's an "IDispatch error #3105", but I can't find any information on this error anywhere. The _com_error has a filed called __vfptr, which seems to have a value of 0x00469707 _com_error::`scalar deleting destructor'(unsigned int), but I don't know if that's related or not. Some of the values I'm passing in are "2003123182300", "20040104124857" these are date and time values. These are the only values I'm getting an exception on and I can't figure out what's wrong. I'm using ADO classes here[^]. Any help is very appreciated as I'm completely dumbfounded by this. If you'd like the code I'm using just let me know. Thanks!
[UPDATE]
Well I just tried manually adding a value like "2003123182300" to the database and received a "Syntax error converting datetime from character string." error. So I guess that's probably why I'm getting the exception, but if I can't add a value like that how do I add an ISO date/time value to the database?
[/UPDATE]
- Aaron
|
|
|
|
|
Is is possible to setup the format of a column so that in a select it has a certain format? For example in Oracle I could do something like:
column columnname format a18
column columnname truncated This would format columnname so that it was only 18 characters wide and would trucate any extra characters. Is there anything like this for SQL Server (I'm using MSDE). Thanks.
- Aaron
|
|
|
|
|
select cast(test_column as char(15)) from test_table
This will truncate the column to 15 characters if it exceeds it, or pad on the right if the column doesn't
select cast(test_column as char(15)) from test_table
test_column
---------------
1234567890
12345
(2 row(s) affected)
select cast(test_column as char(5)) from test_table
test_column
-----------
12345
12345
(2 row(s) affected)
The test_table had two rows, test_column was "1234567890" on the first row and "12345" on the second.
There is also a convert function you may like to look up which gives finer control of the output format (especially for dates) if you need it.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
That helps quite a bit. Thanks very much for the information. The only thing is that with that format you have to do it in every select statement. Is there anyway to make it more global (at least for a session) so that whenever a specific column is involved it gets the format that you give it? If not I can definately use the cast function. Thanks again for the help.
- Aaron
|
|
|
|
|
I've written a fairly simple C# application that reads an MSDE database. The project is to distribute this application and database on CD.
The client would install the application and the database would reamain on cd.
My application works fine, the problem is developing a solid set up routine for deploying the application and MSDE.
A toolkit and a dozen articles exist on the MS site but not one executable example.
Does anyone have a small example of a 'setup' application to install an application, MSDE and it's database.
Thank you,
cb
|
|
|
|