|
it's a raw SQL string. It's no stored procedure, if you'd read my post again.
the error msg is very confusing.
norm
|
|
|
|
|
Use sp_executesql.
The Execute command is for stored procedures.
Julio-SESICO
|
|
|
|
|
Try
EXEC ( @strSQL ) (note the parentheses)
or
sp_executesql @strSQL
Bruce Duncan, CP#9088, CPUA 0xA1EE, Sonork 100.10030 Blackadder: Baldrick, have you no idea what irony is? Baldrick: Yeah, it's like goldy and bronzy only it's made of iron.
|
|
|
|
|
Hey, this solved the problem, thankyou. It will be very hard to find this bug
I've got a new one for you - I think you will solve this with ease:
CREATE PROC dbo.DADA(....) AS
...
... Body of a stored procedure ...
...
DECLARE @token VARCHAR(15)
SET @token=NULL
SET @strSQL = 'SELECT @token=strToken FROM ' + @temp_table_name + ' WHERE rowindex=' + CAST(@index AS VARCHAR(10))
SET @strSQL = CAST(@strSQL AS nvarchar(1000))
EXEC (@strSQL)
...
... Body of a stored procedure ...
...
GO
The error message from Query Analyzer: "Must declare the variable '@token'"
As u can see from the code fragment, @token has been declared.
norm
|
|
|
|
|
hmm, its complaining about @token in the SELECT statement. In this case the SELECT that you have built up is executing in a different 'scope' or 'session' (not sure how best to explain) in which no @token variable is declared.
In this case I would suggest using the sp_executesql stored proc instead on EXEC ( ) , as this allows you to pass variables into the built up statement.
Try something like this (untested)
SET @strSQL = 'SELECT @innerToken=strToken FROM ' + @temp_table_name + ' WHERE rowindex=' + CAST(@index AS VARCHAR(10))
sp_executesql @strSQL, N'@innerToken VARCHAR(15) OUTPUT', @innerToken = @token
Bruce Duncan, CP#9088, CPUA 0xA1EE, Sonork 100.10030 Blackadder: Baldrick, have you no idea what irony is? Baldrick: Yeah, it's like goldy and bronzy only it's made of iron.
|
|
|
|
|
Thanks, i wished i brought this to you earlier.
norm
|
|
|
|
|
Is it possible to SELECT,ONLY from column name?I have some tables that their column name could be anything and I want their NAME only in my program,not value in thei ROW.Is that possible?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I'm not sure if I understood you right.
Maybe you mean how to get the columnnames in you table. Try DESCRIBE tablename
--
karl
|
|
|
|
|
I am attempting to create an ASP.NET application which constantly accesses a database, from all the examples I have seen in the MSDN documentation it says that the connections should be opened and closed for each transactions. However I would like to lock the records that are shown on the screen so that they cannot be edited by another instance. I cannot find any examples of how to: -
1) Keep the connection open the whole time.
2) Pass the DAL object between ASP.NET pages so that I can have multiple pages containing the data.
Chris
|
|
|
|
|
I want to run stored procedure with some paraneters from my asp.net application.I use this code but I got run=time error at the last line:
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlParameter[] parameters =
{
new SqlParameter("@Table", SqlDbType.NVarChar , 50),
new SqlParameter("@ID" , SqlDbType.BigInt , 8)
};
parameters[0].Value = Page.Request.Params["Cat"];
parameters[1].Value = int.Parse(Page.Request.Params["id"]);
SqlCommand command = new SqlCommand();
foreach (SqlParameter parameter in parameters)
{
command.Parameters.Add( parameter );
}
command.Connection = conn;
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "sp_Votes_GetVotes";
if(conn.State == System.Data.ConnectionState.Closed)
conn.Open();
SqlDataReader dr = command.ExecuteReader();
The error is:
Error converting data type nvarchar to bigint.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hiya getting a message saying "Database error - There were no columns specified to retrive." when using these 2 lines:
SqlString = "DELETE * from Branches WHERE Branch_No LIKE '4%' ";
OR
SqlString = "INSERT INTO Branches (Branch_No,Branch_Name) VALUES ('6','Derry') ";
But Branch_No is the first column and Branch_Name is the second..
Am I using the statements wrong??
Thanks,
grahamoj.
|
|
|
|
|
DELETE statement do not need * from.Change it to:
DELETE Branches WHERE Branch_No LIKE '4%'
For second one,Whats the type of columns?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
You don't need the "*" but you'll need "from" so the right statement will be (at least in SQL92)
DELETE FROM branches WHERE branch_no LIKE '4%'
--
karl
|
|
|
|
|
Yes.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Would you have a full list of all the statements( that is right syntax ) available to use for me??
What is the syntax for the INSERT??
Thanks for ur help.
grahamoj.
|
|
|
|
|
Hiya have tried the DELETE as u suggested but still not working for me.
I think I know what it is though. What should this line change to for reading and writing..
// Execute the query
recset.Open( CRecordset::forwardOnly,SqlString,CRecordset::readOnly );
Have tried a "CRecordset::writeOnly, but none exists.
Thanks
grahamoj.
Have also tried this:
recset.Open( AFX_DB_USE_DEFAULT_TYPE,SqlString,CRecordset::none );
|
|
|
|
|
|
Does anyone know how to get the name of the database server I am connecting to with OleDB.NET in C# e.g. is it SQL Server or is it Oracle, etc.
Cheers,
Dave.
|
|
|
|
|
Usually most of that information can be obtained from your OleDbConnection object. Look up the public properties of that class.
Bruce Duncan, CP#9088, CPUA 0xA1EE, Sonork 100.10030 I can levitate birds...
|
|
|
|
|
I've looked at them and that info doesn't seem to be available. Any other ideas?
Ta,
Dave.
|
|
|
|
|
Hey All -
I'm wondering if anyone else has come across a similar problem and/or solution.
I've implemented a desktop application in .NET (C#). In order to increase performance, it maintains a local cache of server-side data in a collection of DataTable objects (since I'm not retrieving this data from a DB, I'm not using the DataAdapter, I'm building these DataTable objects dynamically).
Anyway, in order to optimize the application, I'm refactoring the application to use several threads for different things. Now, the problem this introduces is I no have the possibility of two threads attempting a write operation to the same DataTable object (which, according to the MSDN does not support thread safe write operations -- BOO! )
Rather than write set() methods for all my dataTable objects and look after the write synchronization, I'm wondering if its possible to just create two new objects, perhaps SynchroDataTable and SynchroDataRow that extend DataTable and DataRow respectively and synchronize the appropriate properties. That way, I can multithread my app without writing to much new data access/update code.
Has anyone tried something similar? What were your experiences, strategies?
Any/all comments, suggestions, code, solutions, URLs, etc.. are appreciated!
Regards,
Bill
--
Bill D. Baldasti
Canuck Coder in T-dot!
|
|
|
|
|
Hiya I have only started to learn SQL in MFC/C++. I have a program that opens a ACCESS DATABASE and I can do queries on it no problem using SQL. My question is how is a SQL server accessed??
Is it the same as I have accessed the ACCESS DATABASE?? Normally on a SQL server, are the files all kept as databases and that is how you can access them the same??
Can anyone give me some info on accessing a database on a SQL server..
Thank you.
grahamoj.
|
|
|
|
|
|
How do I go about inserting a string that contains a ' into a table when it is considered the end of my string? I'm using VB - shhhhh! - and I've tried escaping it with a \ but that doesn't seem to help.
[edit]
I'm currently using ADO and trying to use Connection.Execute and a full SQL INSERT statement. Would it be easier to use Recordset.AddNew and then just manually set the fields?
[/edit]
Is it possible?
J
"We cross our bridges when we come to them and burn them behind us, with nothing to show for our progress except a memory of the smell of smoke, and a presumption that once our eyes watered." - Tom Stoppard - Rosencrantz and Guildenstern are Dead.
|
|
|
|
|
Replace("Some string with a ' in it", "'", "''") should do the trick.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|