Can I Access A Database Backwards? (I Really Want To Display The Information Backwards Actually).
Feb 15, 2008
I am new to accessing sql stuff and asp.net I have some code in a .cs page that accesses a sql database and displays the information on a page from top to bottom (press releases: www.managewatch.com/press). I created this site but I used the code from the old site and just implemented it. I'd like to have the press releases display from newest on top to oldest on bottom. Is there a way I can do this? I have included the code in my cs page that does this:
protected void Page_Load(object sender, EventArgs e)
{
// connect to db
SqlConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["xxxx"].ConnectionString);
db.Open();
while (row.Read())
{
Literal pressReleaseTitle = new Literal();
Literal pressReleaseBody = new Literal();
pressReleaseTitle.Text = "<div id='pressheader'>" + row["title"].ToString() + "</div>";
pressReleaseBody.Text = "<div id='pressbody'>" + row["content"].ToString() + "</div><br>";
lblPressReleases.Controls.Add(pressReleaseTitle);
lblPressReleases.Controls.Add(pressReleaseBody);
}
row.Close();
db.Close();
}
I can see what is happening here "cmd.CommandText = "SELECT * FROM press";" tells it to get all the info from "press" but I just don't get the " row = cmd.ExecuteReader();" part. Is this just grabbing one line of the database? what does this code do?
I need to simulate cursor-type (groan) behavior in a dataset and am wondering if this is possible in the foreach task. Example - The user has the need to go through the data row-by-row, and if a certain value is missing in row 10 then go back to row 8, grab a value from that row, and plug it in the missing column in row 10. Then move on to row 11.
Is there a way to make the foreach ADO enumerator travel backwards? Is there a way to do this that will not be awfully inefficient? Any suggestions out there would be welcome.
I've advocated for set-based updates, and these simply aren't an option, as each successive row depends on the updates that may have happened above it in the sequence. Unless I hear of any other ideas out there I have to move forward with this sequential type operation.
I'm sure this question has already been asked, I made an attempt to search the forums, but was unsuccessful. Our production servers are currently running SQL Server 2000 3a. I just got a new development system and have no intentions of installing SQL Server 2000 dev, but SQL Server 2005 Dev Edition. I was wondering if I will still be able to install SQL2005 and still be able to administer/modify 2000 mdfs with SQL 2005 Enterprise Manager. I wanted to be able to still make development on SQL 2k5 and update the production server (SQL2k). This is on my dev system not the production, the production will still be running SQL 2k, until the client decides on purchasing SQL 2k5. Of course I will not be able to use the new db features and types on a SQL2000 server, I just want to maintain the legacy with 05 Enterprise Manager (i.e.: SP, UDF and DTO). Thanks a gig. Larry
what are the SS rules around forwards compatibility? For example, I have a SS2014 DB instance but I'm able to query it through SSMS2012 Express. Also, I backed up a SS2012 database and restored it into a SS2014 instance which works as expected. Should I also be able to back up a SS2014 instance that was restored from SS2012 and restore it into a separate SS2012 instance?
In my script below. I'm trying to update a SQL Server 2000 DB with data from SQL Server 2005. I've written a Cursor to call tables from information schema. Compare the data between 2005 and 2000 then Insert into SQL 2000 Table. But I'm getting The multi-part identifier "c.ID" could not be bound.. Can you please help me to resolve this.
DECLARE TableCursor CURSOR FOR SELECT Table_Name FROM INFORMATION_SCHEMA.TABLES WHERE Table_Type = 'Base Table' and Table_Name like 'L_%'
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName WHILE @@FETCH_STATUS = 0 BEGIN
DECLARE @Line VARCHAR(1000)
SET @Line = ''
SELECT @Line = @Line + 'c.'+ c.Column_Name + ' , ' FROM INFORMATION_SCHEMA.TABLES T JOIN INFORMATION_SCHEMA.COLUMNS C ON t.Table_Name = c.Table_Name WHERE t.Table_Name = @TableName and t.Table_Name like 'L_%'
I'am doing functionality test on DTS packages and saving my DTS packages to meta data services instead of saving them as local packages. We would like to see what information would be provided by saving them this way, but when we try to open the meta data browser (the 3rd icon under DTS) we get the following error:
An error occurred while trying to access the database information. The msdb database could not be opened.
Hello, I'm trying to create a web page that is protected by a user login. I want the user data to be stored in an access database file and not an SQL Server express database.
I was following this guide on msdn: http://msdn2.microsoft.com/en-us/library/879kf95c(VS.80).aspx
However, I was doing everything locally using a file system and not IIS. (Which seemed to work fine)
My main problem is that I cannot get the membership information stored in an access database. The only provider option was one for the SQL server express. I think I will have to make a custom provider? However, I read through some of that documentation and was equally confused. ( http://msdn2.microsoft.com/en-us/library/Aa479031.aspx )
How can I display and retreive information from an SQL Express 2005 database in a Visual Basic Express 2005 application?
I know that I can drag and drop a node onto the form (to display a sort of spreadsheet), but the method I wish to approach is to display information in a text box.
Partial Public Class StoredProcedures <Microsoft.SqlServer.Server.SqlProcedure()> _ Public Shared Sub StoredProcedureTest(ByVal strAS400ServerName As String, _ ByVal strCompany As String, _ ByVal decSerial As Decimal, _ ByVal strSerialCode As String, _ ByVal strSerialScan As String, _ ByVal decMasterSerialNumber As Decimal, _ ByVal strCustomerPart As String, _ ByVal strTakataPart As String, _ ByVal strCustomerRanNo As String, _ ByVal strCustomerAbv As String, _ ByVal strDestinationAbv As String, _ ByVal decQty As Decimal, _ ByVal strCreatDate As String, _ ByVal decVoidSerialNo As Decimal, _ ByVal strProductionLineNo As String, _ ByVal strProcType As String)
Dim sp As SqlPipe = SqlContext.Pipe Dim strResult As Integer = 0 Dim strErrorText As String = String.Empty Dim dsData As New DataSet Dim parameter(15) As OleDbParameter If Not strAS400ServerName Is Nothing And strAS400ServerName <> String.Empty Then ' Populate parameter collection
If dsData.Tables.Count > 0 Then dsData.Tables(0).TableName = "Supreeth" Dim bitresult As String = dsData.Tables(0).Rows(0)(0).ToString() Dim errorstring As String = dsData.Tables(0).Rows(0)(1).ToString()
' I am not sure here SqlContext.Pipe.Send(bitresult) SqlContext.Pipe.Send("No errors")
End If
Else Throw New ArgumentException("AS400Db.GetAS400TraceabilityResult: AS400 server name is empty or invalid") End If
End Sub
Public Shared Sub RunDB2Sp(ByVal strProcedure As String, ByRef parms As OleDbParameter(), ByRef dsData As DataSet) '********************************************* ' Declare Variables '********************************************* Dim daAdaptor As OleDbDataAdapter Dim cmdAS400 As OleDbCommand 'Dim dstestMe As New DataSet Try cmdAS400 = CreateCommand(strProcedure, parms) daAdaptor = New OleDbDataAdapter(cmdAS400)
' Fill the Data Set daAdaptor.Fill(dsData) Catch expError As OleDbException daAdaptor = Nothing Finally daAdaptor = Nothing cmdAS400.Dispose() 'Me.Close()
End Try
End Sub Public Shared Function CreateParameter(ByVal name As String, _ ByVal type As OleDbType, _ ByVal size As Integer, _ ByVal direction As ParameterDirection, _ ByVal paramValue As Object) As OleDbParameter Dim param As OleDbParameter = New OleDbParameter param.ParameterName = name param.OleDbType = type param.Size = size param.Direction = direction param.Value = paramValue Return param End Function
Private Shared Function CreateCommand(ByVal strProcedure As String, ByVal prams As OleDbParameter()) As OleDbCommand Dim CmdSAS400 As OleDbCommand Dim parameter As OleDbParameter Dim connAS400 As OleDbConnection connAS400 = New OleDbConnection("Provider=IBMDA400;Data Source=AHISERIESDEV1;User Id=****;Password=****;") connAS400.Open()
CmdSAS400 = connAS400.CreateCommand() CmdSAS400.CommandText = strProcedure CmdSAS400.CommandType = CommandType.StoredProcedure CmdSAS400.Parameters.Clear() 'CmdAS400.CommandTimeout = intTimeOut If (prams Is Nothing) Then Else For Each parameter In prams CmdSAS400.Parameters.Add(parameter) Next
End If
Return CmdSAS400
End Function
I have a UI which supplies 16 parameters to my stored procedure , which in turn call another sored procedure on as400 which returns result set. So far i am able to send 16 parms and get the values in dataset. My question here how would i send the result set to UI for display, please feel free to comment on any changes need to be made on code . I badly need to find a solution for this and i appreciate any feed backs
hi all, i have a package; thats executing another 4 packages, i can able to execute these packages in ASP.net
I want to display the status notification of the executing packages in the webpage( while packages are being executed, i want to display which package is executing, and what is the status of the package! whether it is executing or not? or it is raising any errors?) every thing i want to give in the front end--> its not my requirement, my client ask me to do that!
so please help me! how to display these status information of the running package in asp.net (c#)
(i'll give you one good chocolate if you give me good solution!)
post your mails to vivekanandaraj.natarajan@honeywell.com Thanks you a lot!
I have a query where I am trying to display the most recent information about travelling method of customers using "t.collection_date". I am struggling to get MAX function working in the query.
SELECT P.id, P.forename, P.surname, P.dob, c.postcode, l.code_des, MAX(t.collection_date) FROM People p, MOT_HIST t, lk_mode_of_travel l, corresp_address c
WHERE p.ID = t.id (+) AND t.mode_of_travel = l.int_code (+) AND p.id = c.entity_id (+)
I want to make a query, stored procedure, or whatever which will only display the primary key where there does no exist a foreign key in linked table.For example. If I had two tables with a one to many relationship.A [Computer] has one or more [Hard Drives]. I want to select only those computers which do not have a Hard Drive(s) associated with them. That is, show all computers where the Computer_ID field in the [Hard Drives] table does not exist. This seems simple but I'm drawing a blank here.
I have recently started using VWD and SQl Express. I want to set up a catalogue of books on sql express of which there are three hundred which will then be presented on a web site. I already have most of the books on an access file. This may sound silly (I'm quite new to programming) but is there any way I can get sql express to extract information from the access file to save me writing it all out again? Thanks nick
I've been unsuccessful getting Reporting Services 2005 to work after reinstalling SQL 2005. The RS service cannot connect to its database, as reported in the Event Log. If I visit http://localhost/Reports, I get the error "Key not valid for use in specified state. (Exception from HRESULT: 0x8009000B) (rsRPCError)"
I've used the RS Config Mgr to create a fresh database for it named SSRS (and SSRSTembDB), and it is set to use Service Credentials in the db connection. The RS service is running using the same admin account as MSSQL, .SQLExec. I have confirmed that .SQLExec is in the RSExecRole role in the SSRS database.
When I created the SSRS database, the Config Mgr had a green check for every step except the last. For "Setting Connection Info for the Reporting Server" there was a yellow '!', with the explanation, "Although saving the database connection succeeded, the report server cannot access internal information about this deployment to determine if the current configuration is valid for this edition. ..."
I examined rsreportserver.config to look for any issues. The <dsn> element has an encrypted string, the <ConnectionType> element says "Default", and the logon elements are empty. I could not find the db names, SSRS and SSRSTempDB, anywhere in the file. Where are these kept? I don't know what else to look for.
Also, in RS Config Mgr, the 'Encryption Keys' page has a blue '!', and only the 'Restore' and 'Delete' buttons are enabled. The 'Initialization' page has a red 'X'. The local RS is not listed (the grid is empty), and clicking the 'Initialize' button does nothing.
I am taking my first stab at a 3 tier architecture within ASP.Net. I have been adding datasets and creating a new Insert to add certain parts to a table. I am trying to add a date field called 'DateAdded' and is setup in SQL as a DateTime. When Visual Studio auto created the dataset, the Insert function is not "DateAdded as Datetime" as I would have expected, but it is "DateAdded as System.Nullable(Of Date)". There is a space in between 'Of' and 'Date'. If I keep the space in there the insert function shows an error that says "Arguement not specified for parameter DateAdded of funtion( etc. etc.). If I take the space out, the error on the insert function goes away but there is an error within the "OfDate" that says "Array bound cannot appear in type specifiers". I am confused on why the date format changed and how I can get a date to go into the database using the autogenerated datasets from Visual Studio. Any help would be appreciated. Thanks, Mike
Till recently we were using the following code to retreive schema information of columns of tables
Dim schemaTable = connection.GetOleDbSchemaTable( _ System.Data.OleDb.OleDbSchemaGuid.Columns, _ New Object() {Nothing, Nothing, tableName, Nothing})
Now instead of getting the name of table (which i was using as param for filtering) i'm going to receive a sql-query. Now my question is if I were to get a query like the following :
Hi,I've just installed SQL server and then IIS and SQLCE tools.I created a virtual directory and was trying to update the NTFSpermissions from SQLServer Connectivity management when i got thefollowing error - Access Control List (structure) invalid.Has anyone come across this and if so, what did u do to fix it.ThanksLyn
I actually work in an organisation and we have to find a solution about the data consistancy in the database. our partners use to send details to the organisation and inserted directly in the database, so we want to create a new database as a buffer database to insert informations from the partners then make an update to the main database. is there a better solution instead of that?
I have a table in SQL, that I know how to connect to using ADO, but Ineed help on how to read records from that table.So on a form I have a listbox where I want to populate that and i havea textbox with a userid.Here is an example of the table:USER ID TYPE PAYMENT=====================0001 CARD 150.000001 CASH 250.000002 CASH 175.00If I have 0001 in the txtuserid textbox, I then want to display inthe listbox:CARD 150.00CASH 250.00How would I do this?thanks
I'm having a weird problem with an easy process. I have a section that allows people to enter their name and email address if they wish to be contacted. I have it set up so that when they enter that information into the text boxes, the info is then sent to my SQL database. The code looks right to me, but it never comes up. Here is the code I have for the button_click.
Dim NTAdatasource As New SqlDataSource() NTAdatasource.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ToString() NTAdatasource.InsertCommandType = SqlDataSourceCommandType.Text NTAdatasource.InsertCommand = "INSERT into ContactUs (YourName, EmailAddress, DateTimeStamp) VALUES (@YourName, @EmailAddress, @DateTimeStamp)" NTAdatasource.InsertParameters.Add("YourName", txtYourName.Text) NTAdatasource.InsertParameters.Add("EmailAddress", txtEmailAddress.Text) NTAdatasource.InsertParameters.Add("DateTimeStamp", DateTime.Now) Dim RowsAdded As Integer = 0 Try RowsAdded = NTAdatabase.Insert() Catch ex As Exception Server.Transfer("problem.aspx") End Try
If RowsAdded <> 1 Then Server.Transfer("problem.aspx") Else Server.Transfer("success.aspx") End If End Sub
The strange thing is that when I debug, the "rowsadded" value comes up to 1. The process runs through debugging just fine and redirects me to my "success.aspx" page. What am I doing wrong?
I work with multiple servers and I have system administrator rights on all server. My question is, why on some server when I click on a database it shows the General, Table & Index, Space Allocated tool bar, than if I go to a different server, click a database it does not show? I would like to see this toolbar on all my servers when I click a database. Thanks Reggie
Pardon the possibly senseless question - I have been an NT Administrator for some years, and have just gotten thrown into picking up some SQL DBA work and I'm still feeling my way around.
Is it possible to query the Master database for the setup information (etc) on the other databases? Several have been marked suspect due to a hard drive failure and I am trying to figure out what the original setup of the databases was.
Hello,I am trying to use the SQl Server database reporting tools to create areport on the database to find areas for optimization including tableformats, column formats, and sizes. Can anybody please help me withthis. If any body has used any other tool by which I can create abovementioned reports plz do let me know. I will be really thankful foryour help.ThanksSuneel
I have a serious problem with either SQL Server or SQL Reporting Services. I have 7 tables in a database that are relational. I have created serveral reports against this database. Last week when I pulled one of the reports, I was missing information on one of the cells. The reason why I know this is because my boss has us verify the report against the database. That took about an hour to complete. When we found that the report was not correct I repulled the report and the cell that was empty, was now populated. What gives? This is the same report I have pulled for the last month and had no problems until now. Is there a time issue involved between the last update to the database to the time I pull the report? Or maybe there is something wrong with the query?
SELECT Lease.[Lease #], MineralContacts.[Mineral Owner First Name], MineralContacts.[Mineral Owner Last Name], Tract.County, Tract.[Tract Number], Tract.[Tract Description], Tract.Section, Tract.Block, Tract.Survey, Tract.Abstract, Lease.[Lease Date], Tract.[Title Check Though], Tract.[2ndTitleReview], Tract.[2nd R/S Complete], Tract.[Title Agent], Tract.[Tract Gross Acres], SubTract.[Tract Net Acres], Draft.[Draft Status], Draft.[Draft Due Date], Draft.[Draft Amount], Draft.[Draft #], Draft.[ANB Invoice #], Draft.[Lse File Sent to CP], Draft.[Money Wired from CP to EA], Draft.[STA Approved Draft for pmt], Draft.[STA Recommend to Return Daft], Draft.[KE Advised ANB to Pay Draft], Draft.[KE Advised ANB to Return Draft], Draft.[Paid Draft Recd], SubTract.Comments, SubTract.Hide FROM Tract INNER JOIN SubTract ON Tract.TractID = SubTract.TractID INNER JOIN Mineral ON SubTract.SubTractID = Mineral.SubTractID INNER JOIN Lease ON Mineral.MineralID = Lease.MineralID INNER JOIN Draft ON Lease.LeaseID = Draft.LeaseID INNER JOIN MineralContacts ON Mineral.MineralID = MineralContacts.MineralID WHERE (Draft.[Draft Status] IS NOT NULL) AND (Draft.[Draft Due Date] IS NOT NULL)
If I had a bunch of paragraphs stored in a database field, is there a way, when displaying that data, that I can write instructions to only retrieve the very first paragraph?
This is probably a very simple question but i am having problems with inserting information into database The function takes the values "FirstName" And "LastName" from A table Called "Customer" and the value "ProductID" from a table called "Products" and inserts them into a table called " NewOrder". Everything compiles ok but when I press the button the information is not uploaded to thedatabase. ( There is no error message) This is the stored procedure CREATE PROCEDURE SP_NewOrder(@CartID char (36), @CustomerID Varchar (50))AS INSERT INTO NewOrder (FirstName, LastName, ProductID) SELECT Customer.FirstName, Customer.LastName, Products.ProductID From Customer,Products Join ShoppingCart ON Products.ProductID =ShoppingCart.ProductIDWHERE ShoppingCart.CartID = @CartID AND Customer.CustomerID = @CustomerIDGO This is the Function Public Shared Function CreateOrder() AS String Dim customerID As integer Dim connection as New SqlConnection(connectionString) Dim command as New SqlCommand("SP_NewOrder",connection) command.CommandType = CommandType.StoredProcedure command.Parameters.Add("@CartID", SqlDbType.Char,36) command.Parameters("@CartID").Value = shoppingCartID command.Parameters.Add("@CustomerID", SqlDbType.Varchar,36) command.Parameters("@CustomerID").Value = customerID Try connection.Open() command.ExecuteNonQuery() Finally connection.Close() End TryEnd Function This is the page code Sub btn3_Click(sender As Object, e As EventArgs)Dim cart as New ShoppingCart()Dim shoppingCartID As IntegerDim customerID As Integer = Context.Session("worldshop_CustomerID")cart.CreateOrder()End Sub Can Anyone see where I am going wrong Many thanks martin
I would like to know how to (if it is at all possible) in SQL (or even ADO) to retrieve all the data concerning database X's
a) Tables b) Tables column names c) Tables column's data types
I don't want to use the doa.tabledefs object.. .i would prefer to do it in SQL, but using ADO objects (since I am developing stuff in VB) would be ok too.
Please Help.. i have been going crazy trying to find anything useful.. email me back please!