Bind Variable In CURSOR
Mar 30, 2006
SQL Server 2000 SP4 with AWE hotfix. Windows 2003 SP1.
I have a stored procedure which is not working the way I think it
should be.
I have a CURSOR which has a variable in the WHERE clause:
DECLARE get_tabs CURSOR local fast_forward FOR
SELECT distinct tablename, id, shcontig1dt, shcontig2dt
FROM db_ind
WHERE dbname = @dbname
ORDER BY tablename
It won't return anything, even when I verify that @dbname has a value
and if I run the query in Query Analyzer with the value, it returns
rows:
SELECT distinct tablename, id, shcontig1dt, shcontig2dt
FROM db_ind
WHERE dbname = 'Archive'
ORDER BY tablename
DB_Rpt_Fragmentation11575791622006-03-29 09:52:11.7772006-03-29
09:52:11.823
DtsAdtStdArchive_DataSourceType5175768822006-03-29
09:52:11.8702006-03-29 09:52:11.887
DtsADTstdArchiveNotUsed3575763122006-03-29 09:52:11.8872006-03-29
09:52:12.103
I've taken out most of the guts for simplicity, but here's what I've
got:
--CREATE TABLE dbo.db_ind
--(
--db_ind_tkintIDENTITY,
-- id int NULL,
-- tablename sysname NOT NULL,
-- indid int NULL,
-- indexname sysname NOT NULL,
-- shcontig1dt datetime NULL,
-- defragdt datetime NULL,
-- shcontig2dt datetime NULL,
-- reindexdt datetime NULL
--)
ALTER PROCEDURE IDR
(@hours int
)
AS
--SET NOCOUNT ON
--SET ANSI_WARNINGS OFF
DECLARE @tabname varchar(100),
@indname varchar(100),
@dbname varchar(50),
@vsql varchar(1000),
@v_hours varchar(4),
@shcontig1dtdatetime,
@shcontig2dtdatetime,
@defragdtdatetime,
@reindexdtdatetime,
@idint,
@indidint,
@rundbcursorint,
@runtabcursorint,
@runindcursorint
DECLARE get_dbs CURSOR local fast_forward FOR
SELECT dbname
FROM db_jobs
WHERE idrdate < getdate() - 4
or idrdate is null
ORDER BY dbname
DECLARE get_tabs CURSOR local fast_forward FOR
SELECT distinct tablename, id, shcontig1dt, shcontig2dt
FROM db_ind
WHERE dbname = @dbname
ORDER BY tablename
DECLARE get_inds CURSOR local fast_forward FOR
SELECT indid, indexname, defragdt, reindexdt
FROM db_ind
WHERE dbname = @dbname
AND tablename = @tabname
ORDER BY indexname
OPEN get_dbs
FETCH NEXT FROM get_dbs
INTO @dbname
IF @@FETCH_STATUS = 0
SELECT @rundbcursor = 1
ELSE
SELECT @rundbcursor = 0
SELECT @v_hours = CONVERT(varchar,@hours)
--================================================== ================================================== =====
--================================================== ================================================== =====
--================================================== ================================================== =====
WHILE @rundbcursor = 1
BEGIN -- db while
PRINT '============================='
PRINT @dbname
PRINT '============================='
--================================================== ================================================== =====
--================================================== ================================================== =====
OPEN get_tabs
FETCH NEXT FROM get_tabs
INTO @tabname, @id, @shcontig1dt, @shcontig2dt
IF @@FETCH_STATUS = 0
BEGIN
PRINT 'table: ' + @tabname
SELECT @runtabcursor = 1
end
ELSE
BEGIN
PRINT 'not getting any tables! '-- <<<<< THIS IS WHERE IT HITS
SELECT @runtabcursor = 0
end
WHILE @runtabcursor = 1
BEGIN
PRINT @dbname
PRINT @tabname
--================================================== ================================================== =====
OPEN get_inds
FETCH NEXT FROM get_inds
INTO @indid, @indname, @defragdt, @reindexdt
IF @@FETCH_STATUS = 0
SELECT @runindcursor = 1
ELSE
SELECT @runindcursor = 0
WHILE @runindcursor = 1
BEGIN
PRINT 'Index:' + @dbname + '.' + @tabname + '.' + @indname
FETCH NEXT FROM get_inds
INTO @indid, @indname, @defragdt, @reindexdt
IF @@FETCH_STATUS = 0
SELECT @runindcursor = 1
ELSE
SELECT @runindcursor = 0
END-- 1st loop through indexes
CLOSE get_inds
--================================================== ================================================== =====
--==========
PRINT 'db.tab: ' + @dbname + '.' + @tabname
--==========
--================================================== ================================================== =====
OPEN get_inds
FETCH NEXT FROM get_inds
INTO @indid, @indname, @defragdt, @reindexdt
IF @@FETCH_STATUS = 0
SELECT @runindcursor = 1
ELSE
SELECT @runindcursor = 0
WHILE @runindcursor = 1
BEGIN
PRINT 'dbname: ' + @dbname
PRINT 'tabname: ' + @tabname
PRINT 'indname: ' + @indname
FETCH NEXT FROM get_inds
INTO @indid, @indname, @defragdt, @reindexdt
IF @@FETCH_STATUS = 0
SELECT @runindcursor = 1
ELSE
SELECT @runindcursor = 0
END -- 2nd loop through indexes
CLOSE get_inds
--================================================== ================================================== =====
FETCH NEXT FROM get_tabs
INTO @tabname, @id, @shcontig1dt, @shcontig2dt
IF @@FETCH_STATUS = 0
SELECT @runtabcursor = 1
ELSE
SELECT @runtabcursor = 0
END-- loop through tables
CLOSE get_tabs
--================================================== ================================================== =====
--================================================== ================================================== =====
PRINT 'Index Maintenence complete. Job report in
[DB_Rpt_Fragmentation]'
PRINT ''
FETCH NEXT FROM get_dbs
INTO @dbname
IF @@FETCH_STATUS = 0
SELECT @rundbcursor = 1
ELSE
SELECT @rundbcursor = 0
END -- loop through databases
CLOSE get_dbs
deallocate get_dbs
deallocate get_tabs
deallocate get_inds
--================================================== ================================================== =====
--================================================== ================================================== =====
--================================================== ================================================== =====
GO
And this is what I'm getting:
=============================
Archive
=============================
(0 row(s) affected)
not getting any tables!
Index Maintenence complete. Job report in [DB_Rpt_Fragmentation]
..
..
..
etc.
Am I missing something obvious?
Thank you for any help you can provide!!
View 1 Replies
ADVERTISEMENT
Jun 19, 2008
select field1 from table1 where field1 = @p_field1
Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@p_field1".
Hi, i'm getting this error, could anybody please explain, how the syntax should be.........thanks
View 8 Replies
View Related
Dec 1, 2007
I am trying to set a variable to be passed to my asp page but the value is not carrying over. I don't even know if this is supposed to work or not below:
<td colspan="3" style="font-size: 10pt; vertical-align: top; color: <%=Div7fontcolor%>; background-color: <%=Div7bgcolor%>; text-align: center; width: 0px;" id="TopBox" runat="server">
The above Div7fontcolor and Div7bgcolor are variables that I set in the VB file as shown below:
Dim obConnection As SqlConnection = New SqlConnection("Data Source=localhostsqlexpress;Initial Catalog=OrgBoard;Integrated Security=True")Dim obCommand As SqlCommand = New SqlCommand("SELECT Divisions.*, Dept19.*, Dept20.*, Dept21.*, ConfigDisplay.* FROM Divisions CROSS JOIN Dept19 CROSS JOIN Dept20 CROSS JOIN Dept21 CROSS JOIN ConfigDisplay", obConnection)
obConnection.Open()Dim dr As SqlDataReader = obCommand.ExecuteReader()
dr.Read()
Dim Div7bgcolor As String = dr("Div7color").ToString().Trim()Dim Div7fontcolor As String = dr("Div7textcolor").ToString().Trim()
dr.Close()
obConnection.Close()
The web page runs fine with no errors but the value does not carry over and change the property correctly.
I am able to set the bgColor value of the TopBox within the VB file if I use "TopBox.BgColor = Div7bgcolor" but I can't set other values on my web page like the font color. If I can do this from the VB file then please correct me. Using variables within the page will allow me to set almost any value but I don't even know if what I want is possible. Any help is greatly apprectiated.
Thank you,
Kris
View 1 Replies
View Related
Dec 7, 2006
I'm not sure about this one so if someone could help I'd appreciate this.
As shown below I've declared a variable name1 to be used in a while statement substituting for an object name in a select statement (2000 SP3a)
and throwing the shown error. Are variables allowed to be used to substitute for object names or is there another problem? Thanks.
View 2 Replies
View Related
Dec 11, 2006
if i have the cursor
cursor:
cursor for
select name
from sysobjects
where type='P' AND category='0'
and wants a variable before sysobjects which equals a table name, so itll be:
cursor for
select name
from @variable..sysobjects
where type='P' AND category='0'
how do i include a variable within a cursor statement
View 16 Replies
View Related
Jul 23, 2005
Hello All,Is there a T-SQL equivalent of the PL/SQL cursor rowtype datatype ?Thanks in advance
View 2 Replies
View Related
Oct 12, 2005
I am currently using a cursor to scroll through sysobjects to extract table names and then extracting relevant column names from syscolumns.
I then need to run the following script:
declare Detail_Cursor cursor for
select @colname, max(len(@colname)) from @table
The message I receive is "must declare variable @table".
Immediately prior to this script I printed out the result of @table which works fine so the variable obviously is declared and populated.
Can anyone let me know what I'm doing wrong or how I can get the same result.
Thanks
View 4 Replies
View Related
Dec 24, 2004
Hi All,
What i am trying to do is concatenate variable "@Where" with CURSOR sql statement,inside a procedure . But, it doesn't seem to get the value for
the @Where. (I tried with DEBUGGING option of Query Analyzer also).
=============================================
SET @Where = ''
if IsNull(@Input1,NULL) <> NULL
Set @Where = @Where + " AND studentid='" + @input1 +"'"
if isnull(@Input2,NULL) <> NULL
Set @Where = @Where + " AND teacherid =' " + @Input2 +"'"
DECLARE curs1 CURSOR SCROLL
FOR SELECT
firstname
FROM
school
WHERE
school ='ABC' + @where
=============================================
Please check my SQL Above and Could somebody tell me how can I attach the VARIABLE with CURSOR sql statement ?
Thanks !
View 3 Replies
View Related
Feb 16, 2004
Hi,
I have a problem on setting the value for the variable in a declared cursor. Below is my example, I have declared the cursor c1 once at the top in a stored procedure and open it many times in a loop by setting the variable @str_var to different values. It seems the variable cannot be set after the cursor declared. Please advise how can I solve this issue.
------------------------------------------------------------------------
DECLARE @str_var VARCHAR(10)
DECLARE @field_val VARCHAR(10)
DECLARE c1 CURSOR LOCAL FOR
SELECT field1 FROM tableA WHERE field1 = @str_var
WHILE (Sometime TRUE)
BEGIN
....
SET @str_var = 'set to some values, eg. ABC123, XYZ123'
OPEN c1
FETCH c1 INTO @field_val
WHILE (@@fetch_status != -1)
BEGIN
PRINT @field_val
...
FETCH c1 INTO @field_val
END
CLOSE c1
END
DEALLOCATE c1
----------------------------------------------------------------------
Thanks a lots,
Vincent
View 4 Replies
View Related
Aug 14, 2007
Hi,
I need a small help. In my stored procedure, i create a table variable and fill it with records based on my query. The ID field within the table is not continous and can have any value in increasing order .e.g. The ID sequence may be like 20, 33, 34, 59, 78, 79... I want to iterate through each record within the table but without using a Cursor. I want to use a loop for this purpose. There are many articles pointing out how to iterate through records in a table variable but that requires the IDs to be continous which is not possible in my case. Can anyone help me solve this problem...
Any help is appreciated...
View 4 Replies
View Related
Nov 17, 1999
When I execute next query on sqlserver 6.5 nested in stored procedure I can see that 'open testCursor' selected rows using new value of @var. When I execute query on sqlserver 7.0 I can see that 'open testCursor' selected rows using value of @var before 'declare ... cursor'. Is there any way to force sqlserver 7.0 to proccess cursor like it did it before.
select @var = oldValue
declare testCursor cursor
for select someColumns
from someTable
where someColumn = @var
select @var = newValue
open testCursor
fetch next from testCursor into @someColumns
Thank's in advance.
Mirko.
View 2 Replies
View Related
Oct 13, 2003
I'm trying to build a select statement for a CURSOR where part of the SQL statement is built using a variable.
The following fails to parse:
Declare Cursor1 Cursor
For
'select table_name from ' + @database + '.Information_Schema.Tables Where Table_Type = ''Base Table'' order by Table_Name'
Open cursor1
That doesn't work, I've also tried using an Execute() statement, no luck there either. Any ideas or suggestions are greatly appreciated.
View 7 Replies
View Related
Jun 7, 2004
I can't seem to get a cursor to work when I'm passing in a variable for a column name of the select statement. For example:
declare @col varchar(50)
set @col = 'Temperature'
declare notifycurs cursor scroll for
select @col from Table
Obviously this won't work correctly (since the result will simply be 'Temperature' instead of the actual float value for temperature). I tried to use quotes for the entire statement with an EXEC
(ie. exec('select '+@col+' from Table' )
but that gave me an error.
Is there a way to pass in a variable for a column name for a curor select statement????
View 7 Replies
View Related
Dec 10, 2005
I'm trying something like:
UPDATE tbl SET @varFieldName = @varValue
The procedure runs, and when I PRINT @varFieldName, it looks fine, but the table isn't getting updated, and no errors, wierd.
I have the CURSOR open for update, but I didn't list the field names, that shouldn't be a problem, as all fields should be updateable then.
To get the field name, I :
SET @varFieldName = 'SomeChars' + LTRIM(STR(asmallint)) + 'SomeMoreChars'
Thanks,
Carl
View 2 Replies
View Related
Jul 5, 2006
Hi,
here is the code segment below;
...
DECLARE find_dates CURSOR FOR
SELECT @SQL = 'select DISTINC(Dates) from ['+@name+'].dbo.['+@t_name+'] order by [Dates] ASC'
EXEC (@SQL)
but it gives error, variable assignment is not allowed in a cursor declaration. I need to use dynamic SQL , the only way to access all the dbs and their tables inside. Please help.
thanks
View 8 Replies
View Related
Feb 1, 2007
Hello All,
A select statement returns one column with more than one rows.Is there a way to store it in sql Variable without using a Cursor.
Thank you in advance
View 1 Replies
View Related
Jan 28, 2008
Hello,
I have searched the net for an answer but could not find one. When I declare a table variable
and then try to insert fetched row into the table variable like:
Code Snippet
declare @table table (col1 nvarchar(50), col2 nvarchar(50))
declare curs for
select * from sometable
open curs
fetch next from curs into @table
it does not work. any help would be great.
thnx
View 6 Replies
View Related
May 8, 2014
I am using a cursor (i know - but this is actually something that is a procedural loop).
So effectively i have a table of names of stored procedures. I now have a store proc that loops around these procs and runs each one in order.
Now i am thinking i would like to be able to set the table it loops around in a variable at the start - is it possible to do this? So effectively use a tablename in a variable to use in the sql to define a cursor?
View 6 Replies
View Related
Sep 9, 2014
The below cursor is giving an error
DECLARE @Table_Name NVARCHAR(MAX) ,
@Field_Name NVARCHAR(MAX) ,
@Document_Type NVARCHAR(MAX)
DECLARE @SOPCursor AS CURSOR;
SET
@SOPCursor = CURSOR FOR
[Code] ....
The @Table_Name variable is declared, If I replace the delete statement (DELETE FROM @Table_Name ) with (PRINT @table_name) it works and print the table names.
Why does the delete statement give an error ?
View 3 Replies
View Related
Jul 23, 2005
After trying every way I could come up with I can't get a filter clauseto work with a passed variable ...I have a cursor that pulls a filter string from a table (works OK),then I want to use that filter in a second cursor, but can't get thesyntax ...@bakfilter is equal to "MISV2_db_%.BAK" before I try to open and fetchfrom the second cursor. Here is the cursor declaration:DECLARE curFiles CURSOR FORSELECT FileName, FileDateFROM DataFileWHERE (((Active)=1) AND ((FileName) LIKE '@bak_filter'))ORDER BY FileDate DESCWhat do I need to do to get it to use the string contained in@bak_filter?Thanks in advance, Jim
View 1 Replies
View Related
Jun 7, 2006
Hi All,
I failed to find record when using variable in cursor in WHERE clause:
ID is uniqueidentifier field in the table
DECLARE @EncounterID uniqueidentifier
........
WHERE ID = @EncounterID -> this does not work, though @EncounterID is set properly and can see its value in debugger
WHERE ID = 'E3AE2C5B-06F2-4A3C-A3A4-7D6CC43DE012' -> this works fine and record found
Tried to CAST(@EncounterID as char(40)) but still no luck.
I would greatly appreciate any advise hot to make it working.
Thank you very much in advance
Roman
View 4 Replies
View Related
Mar 28, 2000
Hi
I am ramesh here from go-events.com
I am using sql mail to send out emails to my mailing list
I have difficulty combining a select statement with a where clause stored in a variable inside a cursor
The users select the mail content and frequency of delivery and i deliver the mail
I use lots of queries and a stored procedure to retrieve thier preferences. In the end i use a cursor to send out mails to each of them.
Because my query is dynamic, the where clause of my select statement is stored in a variable. I have the following code
that does not work
For example
DECLARE overdue3 CURSOR
LOCAL FORWARD_ONLY
FOR SELECT DISTINCT Events.E_Name, Events.E_SDate, Events.E_City, Events.E_ID FROM Events, IndustryEvents + @sqlquery2
OPEN overdue3
I get an error message at the '+' sign
which says, cannot use empty object or column names, use a single
space if necessary
How do I combine the select statement with the where clause?
Help me...I need help urgently
View 1 Replies
View Related
Oct 3, 2006
Hi all.
I am stuck in a bit of a conundrum for quite a while now, and I hope someone here will help me figure this one out.
So, first things first: let me explain what I need to do. I am
designing a web application that will allow users to consult info
available in a SQL2000 database. The user will enter the search
criterea, and hopefully the web page will show matching results.
The problem is the results shown aren't available per se in the DB, I
need to process the data a bit. I decided to do so on the SQL Server
side, though the use of cursors. So, when a user defines his search
criteria, I run a stored procedure that begins by building a dynamic
sql query and creating a cursor for it. I used a global cursor in order
to do so. It looked something like this:
SET @sqlQuery = ... (build the dinamic sql query)
SET @cursorQuery = 'DECLARE myCursor CURSOR GLOBAL FAST_FORWARD FOR ' + @sqlQuery
EXEC @cursorQuery
OPEN myCursor
FETCH NEXT FROM myCursor INTO ...
CLOSE myCursor
DEALLOCATE myCursor
This works fine, if there's only one instance of the
stored procedure running at a time. Should another user connect to the
site and run a search while someone's at it, it'll fail due to the
atempt to create a cursor with the same name.
My first thought was to make the cursor name unique, which led me to:
...
SET @cursorName = 'myCursor' + @uniqueUserID
SET @cursorQuery = 'DECLARE '+ @cursorName + 'CURSOR FAST_FORWARD FOR ' + @sqlQuery
EXEC @cursorQuery
...
The problem with this is that I can't do a FETCH NEXT FROM @cursorName since
@cursorName is a char variable holding the cursor name, and not a
cursor variable. So to enforce this unique name method the only option
I have is to keep creating dynamic sql queries and exucting them. And
this makes the sp a bitch to develop and maintain, and I'm guessing it
doesn't make it very performant.
So I moved on to my second idea: local cursor variables. The problem with
this is that if I create a local cursor variable by executing a dynamic
query, I can't extract it from the EXEC (or sp_executesql) context, as
it offers no output variable.
I guess my concrete questions are:
Is it possible to execute a dynamic sql query and extract a (cursor) variable from it?Is it possible to populate a local cursor variable with a global cursor, by providing the global cursor's name?Can I create a local cursor variable for a dynamic sql query? How?
Anybody sees another way arround this?Thanks in advance,
Carlos
View 3 Replies
View Related
Aug 12, 2015
In MSDN file I read about static cursor
STATIC
Defines a cursor that makes a temporary copy of the data to be used by the cursor. All requests to the cursor are answered from this temporary table in
tempdb; therefore, modifications made to base tables are not reflected in the data returned by fetches made to this cursor, and this cursor does not allow modifications
It say's that modifications is not allowed in the static cursor. I have a questions regarding that
Static Cursor
declare ll cursor global static
for select name, salary from ag
open ll
fetch from ll
while @@FETCH_STATUS=0
fetch from ll
update ag set salary=200 where 1=1
close ll
deallocate ll
In "AG" table, "SALARY" was 100 for all the entries. When I run the Cursor, it showed the salary value as "100" correctly.After the cursor was closed, I run the query select * from AG.But the result had updated to salary 200 as given in the cursor. file says modifications is not allowed in the static cursor.But I am able to update the data using static cursor.
View 3 Replies
View Related
Jul 20, 2005
Hello,I have a test database with table A containing 10,000 rows and a tableB containing 100,000 rows. Rows in B are "children" of rows in A -each row in A has 10 related rows in B (ie. B has a foreign key to A).Using ODBC I am executing the following loop 10,000 times, expressedbelow in pseudo-code:"select * from A order by a_pk option (fast 1)""fetch from A result set""select * from B where where fk_to_a = 'xxx' order by b_pk option(fast 1)""fetch from B result set" repeated 10 timesIn the above psueod-code 'xxx' is the primary key of the current Arow. NOTE: it is not a mistake that we are repeatedly doing the Aquery and retrieving only the first row.When the queries use fast-forward-only cursors this takes about 2.5minutes. When the queries use dynamic cursors this takes about 1 hour.Does anyone know why the dynamic cursor is killing performance?Because of the SQL Server ODBC driver it is not possible to havenested/multiple fast-forward-only cursors, hence I need to exploreother alternatives.I can only assume that a different query plan is getting constructedfor the dynamic cursor case versus the fast forward only cursor, but Ihave no way of finding out what that query plan is.All help appreciated.Kevin
View 1 Replies
View Related
Sep 20, 2007
I'm trying to implement a sp_MSforeachsp howvever when I call sp_MSforeach_worker
I get the following error can you please explain this problem to me so I can over come the issue.
Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 31
Could not complete cursor operation because the set options have changed since the cursor was declared.
Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 32
Could not complete cursor operation because the set options have changed since the cursor was declared.
Msg 16917, Level 16, State 1, Procedure sp_MSforeach_worker, Line 153
Cursor is not open.
here is the stored procedure:
Alter PROCEDURE [dbo].[sp_MSforeachsp]
@command1 nvarchar(2000)
, @replacechar nchar(1) = N'?'
, @command2 nvarchar(2000) = null
, @command3 nvarchar(2000) = null
, @whereand nvarchar(2000) = null
, @precommand nvarchar(2000) = null
, @postcommand nvarchar(2000) = null
AS
/* This procedure belongs in the "master" database so it is acessible to all databases */
/* This proc returns one or more rows for each stored procedure */
/* @precommand and @postcommand may be used to force a single result set via a temp table. */
declare @retval int
if (@precommand is not null) EXECUTE(@precommand)
/* Create the select */
EXECUTE(N'declare hCForEachTable cursor global for
SELECT QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME)
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = ''PROCEDURE''
AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME)), ''IsMSShipped'') = 0 '
+ @whereand)
select @retval = @@error
if (@retval = 0)
EXECUTE @retval = [dbo].sp_MSforeach_worker @command1, @replacechar, @command2, @command3, 0
if (@retval = 0 and @postcommand is not null)
EXECUTE(@postcommand)
RETURN @retval
GO
example useage:
EXEC sp_MSforeachsp @command1="PRINT '?' GRANT EXECUTE ON ? TO [superuser]"
GO
View 7 Replies
View Related
Mar 15, 2006
Since SQL Express only runs on one CPU, is there a way to bind SQL Express to a particular CPU, or SQL Express only runs on CPU0?
And in case of CPU hyperthreading, I assume that the CPU SQL Express running on will be a logical CPU, not a physical CPU, am I right?
View 3 Replies
View Related
Nov 22, 2006
Hi all,I would like to do something I thought was simple but I can't seem to figure it out. I would like to bind the Text properties to two labels to the columns in an SqlDataSource, much the same as you can bind a listbox to a SqlDataSource.Is this possible?The reason why I'm trying it this way is because I originally used an OleDB connection and datareader, but it doesn't seem to work on our service providers server (keeps saying that it can't find the database) even though it works on the four other server's I've tried. It definitely connects to the database when I use the SqlDataSource on a listbox control, but it fails when I use the same connection string with the OleDB connection.Is this the best way to go about it, or should I persist with finding the OleDB/datareader (the service provider has been no help at all). Thanks.
View 1 Replies
View Related
Feb 18, 2007
My code behind file builds a select statement and I would like to fill an SqlDataSource control with it. Can some show me an example of how I might do that? Maybe something like this?
Me.SqlDataSourceSearchResult.ConnectionString = "ConnectStr"
Me.SqlDataSourceSearchResult.SelectCommand = "SelectStatement"
gvSearchResult.DataSource = Me.SqlDataSourceSearchResult
gvSearchResult.DataBind()
View 5 Replies
View Related
Jun 11, 2004
I tried to install SQL Server 2K on a W2K server running IIS and SSL. The SQL installation failed until I deleted the certs from my system. Now, the SQL logs say "SuperSocket Info: Bind failed on TCP port 1433". I have tried everything on the MS KB, TechNet, and MSDN sites that I could find. I have also uninstalled IIS and Certificate Services from the server. Since there are no certs left, I suspect that SQL Server is getting in it's own way on startup. Does anyone know of a way to trap/log this kind of conflict?
View 14 Replies
View Related
Aug 29, 2006
I use SQLDataSource, bind to a GridView and a SelectParameter that gets it's value from a textbox. If the textbox is empty, then it returns all rows.How do I prevent the query and binding when the page first load? Thanks
View 11 Replies
View Related
Jun 20, 2007
Hello all,I just have problems to bind the data to dropdownlists, and my code is written as: SqlConnection myConnection; SqlCommand myCommand; SqlDataReader myReader; myConnection = new SqlConnection(); myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["NorthWindConnectionString"].ConnectionString; myCommand = new SqlCommand(); myCommand.CommandText = "select PostalCode from Customers order by PostalCode asc"; myCommand.CommandType = CommandType.Text; myCommand.Connection = myConnection; myCommand.Connection.Open(); myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); DropDownList1.DataSource = myReader; DropDownList1.DataBind(); myCommand.Dispose(); myConnection.Dispose();Any idea? Thanks
View 3 Replies
View Related
Nov 7, 2007
my question is what all can i bind my results of a select query to.i know we can use Dataset and Sqldatareader. can we use something else like hashtables. for example we can have:reader = cmd.ExecuteReader(); can we have something likeHashtable = cmd.ExecuteReader();
View 5 Replies
View Related