Fail To Read Entire Table In .NET
Sep 20, 2007
The problem that I am having is that I am not getting the results from an entire table, just a small subset. The sql command is "Select * from login", which has always implied to me, get everything, to end of table, or, until I tell you to stop. I am getting exactly, 10 items as input, and then it stops. I am including the code below in the hopes that someone can spot what it is that I am doing wrong.
The purpose of the routine is to convert a user login database into a new, expanded format.
TIA, Tom
Imports Common.Utility.Utils
Partial Class UserDatabaseConversion
Inherits System.Web.UI.Page
Dim sqlConn As SqlConnection = getSQLConnection(ConfigurationManager.AppSettings("utilityDbName"))
Dim sqlConnN As SqlConnection = getSQLConnection(ConfigurationManager.AppSettings("utilityDbName"))
Dim sqlStringOld As String = "Select * from login"
Dim sqlStringNew As String = "usp_UT_AddNewUser"
Dim buildCnt As Integer = 0
Dim oldUserCnt As Integer = 0
Dim newUserCnt As Integer = 0
Dim oLocation As String = Nothing
Dim errors As Integer = 0
Dim mesg As String = Nothing
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
getOldUsers()
End Sub
Sub getOldUsers()
Dim odate As Date = Date.Today
Dim sqlCmdOld As SqlCommand = New SqlCommand()
sqlCmdOld.CommandText = sqlStringOld
sqlCmdOld.CommandType = CommandType.Text
sqlCmdOld.Connection = sqlConn
Dim dbReader As SqlDataReader = Nothing
Try
sqlConn.Open()
dbReader = sqlCmdOld.ExecuteReader()
If dbReader.HasRows Then
Do While dbReader.Read()
oldUserCnt += 1
Select Case IsDBNull(dbReader.Item("reg_date"))
Case True
buildNewUser(dbReader.Item("name"), dbReader.Item("password"), dbReader.Item("email"), dbReader.Item("type"), dbReader.Item("org"), dbReader.Item("occupation"), dbReader.Item("location"), odate)
Case False
buildNewUser(dbReader.Item("name"), dbReader.Item("password"), dbReader.Item("email"), dbReader.Item("type"), dbReader.Item("org"), dbReader.Item("occupation"), dbReader.Item("location"), dbReader.Item("reg_date"))
End Select
Loop
End If
Catch ex As Exception
Finally
sqlConn.Dispose()
End Try
If errors = 0 Then
lblMesg.Text = "Conversion completed succesfully.<br />Users In: " & oldUserCnt & " , Users Out:" & newUserCnt
Else
lblMesg.Text = "Conversion comleted with errors.<br />Users In: " & oldUserCnt & " , Users Out:" & newUserCnt & "<br />"
lblMesg.Text += mesg
End If
End Sub
Sub buildNewUser(ByVal oname As String, ByVal opassword As String, _
ByVal oemail As String, ByVal otype As String, _
ByVal oorg As String, ByVal oocc As String, _
ByVal oloc As String, ByVal oregdate As Date)
Dim sqlCmdNew As SqlCommand = New SqlCommand()
sqlCmdNew.CommandText = sqlStringNew
sqlCmdNew.CommandType = CommandType.StoredProcedure
sqlCmdNew.Connection = sqlConnN
Dim userName As String = Nothing
Dim firstName As String = Nothing
Dim middleName As String = Nothing
Dim lastName As String = Nothing
Dim title As String = Nothing
Dim emailAddress As String = Nothing
Dim passWord As String = Nothing
Dim userType As String = Nothing
Dim org As String = Nothing
Dim occ As String = Nothing
Dim loc As String = Nothing
Dim rdate As Date = Nothing
oLocation = oloc
' user name will be the first part of the email address
emailAddress = oemail
Dim uname() As String = oemail.Split("@")
' extend the length of the user name to at least 5 characters
Select Case uname(0).Length
Case Is > 4
userName = uname(0)
Case Is = 4
userName = uname(0) & "1"
Case Is = 3
userName = uname(0) & "12"
Case Is = 2
userName = uname(0) & "123"
Case Is = 1
userName = uname(0) & "1234"
End Select
' check for suffixes
Dim suffix() As String = oname.Split(",")
Select Case suffix.Length > 1
Case True
title = suffix(1)
End Select
' split names out
Dim names() As String = suffix(0).Split(" ")
' possibly 3 components to the name
Select Case names.Length
Case Is = 1
firstName = names(0)
Case Is = 2
firstName = names(0)
lastName = names(1)
Case Is = 3
firstName = names(0)
middleName = names(1)
lastName = names(2)
End Select
' setup password. must be at least 6 characters.
' if less, extend to 6.
Select Case opassword
Case Is > 5
passWord = opassword
Case Is = 5
passWord = opassword & "1"
Case Is = 4
passWord = opassword & "12"
Case Is = 3
passWord = opassword & "123"
Case Is = 2
passWord = opassword & "1234"
Case Is = 1
passWord = opassword & "12345"
End Select
' user type, organization and occupation
userType = otype
org = oorg
occ = oocc
' registration date
Select Case IsDBNull(oregdate) Or IsNothing(oregdate)
Case True
rdate = Today.Date
Case False
rdate = oregdate
End Select
' try to extract the location
' get the country
Dim country As String = getCountry(oloc)
' get the state
Dim state As String = getState(oloc)
' only thing left is the city
Dim city() As String = oloc.Split(",")
' add parameter values
sqlCmdNew.Parameters.AddWithValue("@NamePrefix", System.DBNull.Value)
sqlCmdNew.Parameters.AddWithValue("@FirstName", replaceSingleQuote(firstName))
Select Case IsNothing(middleName)
Case True
sqlCmdNew.Parameters.AddWithValue("@MiddleName", System.DBNull.Value)
Case False
sqlCmdNew.Parameters.AddWithValue("@MiddleName", replaceSingleQuote(middleName))
End Select
Select Case IsNothing(lastName)
Case True
sqlCmdNew.Parameters.AddWithValue("@LastName", System.DBNull.Value)
Case False
sqlCmdNew.Parameters.AddWithValue("@LastName", replaceSingleQuote(lastName))
End Select
sqlCmdNew.Parameters.AddWithValue("@UserName", replaceSingleQuote(userName))
Select Case IsNothing(title)
Case True
sqlCmdNew.Parameters.AddWithValue("@NameTitle", System.DBNull.Value)
Case False
sqlCmdNew.Parameters.AddWithValue("@NameTitle", title)
End Select
sqlCmdNew.Parameters.AddWithValue("@Password", replaceSingleQuote(passWord))
sqlCmdNew.Parameters.AddWithValue("@EmailAddress", emailAddress)
sqlCmdNew.Parameters.AddWithValue("@PasswordHint", userName)
Select Case isEmpty(org)
Case True
sqlCmdNew.Parameters.AddWithValue("@Organization", System.DBNull.Value)
Case False
sqlCmdNew.Parameters.AddWithValue("@Organization", replaceSingleQuote(org))
End Select
Select Case isEmpty(occ)
Case True
sqlCmdNew.Parameters.AddWithValue("@Occupation", System.DBNull.Value)
Case False
sqlCmdNew.Parameters.AddWithValue("@Occupation", replaceSingleQuote(occ))
End Select
sqlCmdNew.Parameters.AddWithValue("@Address1", System.DBNull.Value)
sqlCmdNew.Parameters.AddWithValue("@Address2", System.DBNull.Value)
Select Case isEmpty(city(0))
Case True
sqlCmdNew.Parameters.AddWithValue("@City", System.DBNull.Value)
Case False
sqlCmdNew.Parameters.AddWithValue("@City", replaceSingleQuote(city(0)))
End Select
sqlCmdNew.Parameters.AddWithValue("@ZipCode", System.DBNull.Value)
sqlCmdNew.Parameters.AddWithValue("@PostalCode", System.DBNull.Value)
Select Case IsNothing(state)
Case True
sqlCmdNew.Parameters.AddWithValue("@State", System.DBNull.Value)
Case False
sqlCmdNew.Parameters.AddWithValue("@State", state)
End Select
sqlCmdNew.Parameters.AddWithValue("@Other", System.DBNull.Value)
Select Case IsNothing(country)
Case True
sqlCmdNew.Parameters.AddWithValue("@Country", System.DBNull.Value)
Case False
sqlCmdNew.Parameters.AddWithValue("@Country", country)
End Select
sqlCmdNew.Parameters.AddWithValue("@GeneralEmail", False)
sqlCmdNew.Parameters.AddWithValue("@FundRaiseEmail", False)
sqlCmdNew.Parameters.AddWithValue("@GeneralUSPSMail", False)
sqlCmdNew.Parameters.AddWithValue("@FundRaiseUSPSMail", False)
sqlCmdNew.Parameters.AddWithValue("@DateAdded", rdate)
sqlCmdNew.Parameters.AddWithValue("@DateUpdated", rdate)
sqlCmdNew.Parameters.AddWithValue("@Active", True)
sqlCmdNew.Parameters.AddWithValue("@UserType", userType)
Dim iRows As Integer = 0
' try to insert the row into the table
Try
sqlConnN.Open()
iRows = sqlCmdNew.ExecuteNonQuery()
If iRows <> 1 Then
errors += 1
mesg += "<br />User: " & firstName & " " & lastName & " was not added.<br />"
End If
newUserCnt += 1
Catch ex As Exception
Dim exMsg As String = ex.Message.ToString()
writeApplicationLog(exMsg, ConfigurationManager.AppSettings("UtilityDBName"))
errors += 1
mesg += "<br />User: " & firstName & " " & lastName & " was not added due to " & exMsg & "<br />"
Finally
sqlConnN.Close()
sqlCmdNew.Dispose()
End Try
End Sub
Function getState(ByVal loc As String) As String
Dim state As String = Nothing
If loc.Contains("NY") Then
state = "NY"
ElseIf loc.Contains("WA") Then
state = "WA"
ElseIf loc.Contains("PA") Then
state = "PA"
ElseIf loc.Contains("AZ") Then
state = "AZ"
ElseIf loc.Contains("MI") Then
state = "MI"
ElseIf loc.Contains("WI") Then
state = "WI"
ElseIf loc.Contains("CT") Then
state = "CT"
ElseIf loc.Contains("NC") Then
state = "NC"
ElseIf loc.Contains("CA") Then
state = "CA"
ElseIf loc.Contains("NY") Then
state = "NJ"
End If
Return state
End Function
Function getCountry(ByVal cntry As String) As String
Dim country As String = "US"
If cntry.Contains("Canada") Then
country = "CA"
End If
Return country
End Function
End Class
View 1 Replies
ADVERTISEMENT
Mar 1, 2006
Rather than setting by session I would like to configure the DB as readuncommitted.Thanx Advance.
View 5 Replies
View Related
May 16, 2006
Hi! I've some data in a table, and I want to add these records to another table, but I tried yet with select ... Into ... and I lose all the data from this one. I need to ADD the data from table to table. Any suggestion?
Thx
View 3 Replies
View Related
Jul 23, 2005
Hi,I need to lock a table so that Inserts are prevented as well as deleted andupdates. At present I'm thinking this might do it:SELECT * FROM myTable WITH(UPLOCK)but then again I'm not sure whether this will cover the insert case.Thanks,Robin
View 5 Replies
View Related
Mar 13, 2008
How can I do in order that a table show all its rows in a page?And if the table can only show a number of rows cause arrive to the end of the page show the table in the next page?
Thanks!
View 5 Replies
View Related
Feb 19, 2006
I am giving the following statement outside the begin tran block in a stored procedure:
select * from table1 with (holdlock) where column1 = @colValue
I have the following two questions regarding above situation:
Being outside the begin tran block, will the select statement cause a lock to be held or it has to be within the begin tran block for the lock to be held?
Will the select statement hold a lock only on the row or rows matching the where clause, or it may lock a page or even the entire table in this situation?
Thanks
View 3 Replies
View Related
Aug 17, 1999
How can I instruct SQL Server to keep entire table in memory? ie the memory pages should not be swapped to HD.
View 2 Replies
View Related
Jul 20, 2005
I'm a newbie to script writing. I'm trying to write a script to copy alldata from a table to the same table in a 2nd database. Both databases areon the same server and are identical in design. I can do this with DTS butwanted a script I could email to a user to run in Query Analyzer.Example:Copy entire table called 'Customers' in the 'Data01' database totable 'Customers' in the 'Data02' databaseI want to overwrite all data in the destination table.Thanks
View 1 Replies
View Related
Mar 5, 2008
I have table in my SQL database, I want to copy(or insert) one record(one entire row using primary key, which is auto)
I am thinking something like this
Insert Into Table1 (a, b, c,d,e) values(select a,b,c,d,e from Table1 where Primarykey=1 or any number)
telll me how do I do that
maxs
View 4 Replies
View Related
Feb 11, 2008
Hello,
I have a table that I want to cache. So, if this is my query "SELECT * FROM myTable" that I create the cache from, how can I filter the data?
I really need to cache the whole table, since there are a myriad of different statements being executed against the table, so just caching a specific query won't do.
I've found the best approach to make a question is writing it in code, so how can I do the following:
SELECT ColNames FROM MyTableWhichShouldNowBeCached WHERE whereColumns=someParams.
ColNames and someParams make up for a variation of about to 120 different queries. I use SQL 2005 express edition with advanced services.
Cheers!
/Eskil
View 2 Replies
View Related
May 26, 2000
Hi Guys!
This SQL statement, though carefully written to delete only selected rows, deletes the entire A_Shift_Times table:
DELETE FROM A_Shift_Times
WHERE EXISTS (
SELECT 1
FROM
Users
WHERE
(A_Shift_Times.time_in >= CONVERT(DATETIME, '2000-05-29 00:00:00', 102)) AND
((Users.User_Password LIKE N'mrr%') OR (Users.User_Password LIKE N'work%')))
What gives? What am I doing wrong here?
View 1 Replies
View Related
Aug 19, 2002
Hi everybody,
We are using SQl-2000 Sp2 clustured on two compaq servers
We have to modify our database shema every month.
We are using sp_repladdcolum and sp_repldropcolum to
modify table without snapshot.
Owever I would like to add/delete entire table in shema
database without using snapshot ?
Is it possible ?
How to do ?
Thanks.
Fabio
View 1 Replies
View Related
Oct 21, 2014
I convert EBCDIC file to text file at C:orderorder.txt. There are about 1400000 rows. The length of line is 1500.
How to insert entire line into one column of the table? (only one column, named as [LineDetail])
View 1 Replies
View Related
Sep 18, 2013
I'm trying to create a query that searches an entire database for keywords inside of the columns for each table within the database. For instance my tables have 2 columns one named ID and the other Permission, I'd like it be able to return all the lines that are associated with that keyword. So if I search "Schedule" it returns all the lines containing that word in it within that database.
View 6 Replies
View Related
Nov 16, 2015
I usually go for the largest datafile and then query in-there...But now I need to automate it for several instances... I need to be able with one script quickly retrieve the top 5 largest tables for the entire instance,not by database...
View 3 Replies
View Related
Jul 9, 1998
I have a client that has a table that after recreating the database from scratch it has a table that can not drop one of the eight indexes. Has anyone seen something like that? What did you do?
Thanks,
Steven Dunker
View 1 Replies
View Related
Nov 17, 2011
Any easy way for a batch file or automated process to read from one db and table and what ever entry is missing out of another database + table it writes those missing entries to.
This is a simple table in one db that is filled with usernames, I want to see if there are missing usernames in another db and table and write those entries.
db1.usr_table.usr_name = jdoenew
If jdoenew is missing in the 2nd db I will need to write entries like:
db1.usr_table.usr_name = jdoenew
db1.usr_table.password = tmppassword
db1.usr_table.active = 1
View 1 Replies
View Related
Feb 12, 2008
Hey ,
I have sql server 2000, and i am using Microsoft Application block.
I have Transaction Like...
SqlConnection conn = new SqlConnection(ASLConnectionString); conn.Open(); SqlTransaction Trans = conn.BeginTransaction(IsolationLevel.ReadUncommitted);
But If i have another process that try to read the Table if that old transaction running.. it wouldn't Allow me to read the DATA.
i tried Isolation level "snapshot" but that works under sql server 2005 only. so i can not use that. And i have some services that will run during day time.
So if anybody have solution to read the data from table...from sql server 2000 even if another transaction is running?
Please Give any guideline..Help will be appriciated.
thanks & regards,
Nirav Patel
View 1 Replies
View Related
Aug 9, 2004
Hello,
I was wondering how to make a table read-only. I want to make a script that creates a table, adds some data to it, then makes the table read-only to prevent someone from accidentally changing the values.
Thanks to anyone who can help,
Chris
View 2 Replies
View Related
May 11, 2004
Hi
I need a SP to read table A (1000 records) and updates Table B. I think I have to use Cursor, but I'm not very good at writing SP. Any help would be appreciated. Thanks.
View 2 Replies
View Related
Oct 17, 2001
Hi, we're trying to read from a table and write back to the same table and are having a lot of trouble with blocking. What could we do to prevent our application from hanging due to blocking of this type?
View 1 Replies
View Related
Dec 7, 2014
I need to read a db Table but sorted by index - is there a generic "select * from tableA sorted by index" where it just uses whatever index it finds (main index) or do i have to name the index?
View 2 Replies
View Related
Apr 7, 2004
Is it possible to make a table (or set of tables) within a SQL Server database read only (still granting the db_datawriter fixed database role to database users) without dropping and recreating the db_datawriter database role?
View 1 Replies
View Related
May 9, 2008
hi
i want read table name in database in sql while loop statement
View 7 Replies
View Related
Apr 17, 2008
I work on an MS Access project ( *.apd - file) that is linked with a
SQL-express server 2005 (local installed). On this server are 2 databases x
and y.
I linked some tables of database x to y and here's the problem: the linked
tables are read-only.
My authentication for the server is Windows authentication and I'm
administrator.
I say this because I think the problem is a security problem.
when I try to change data in the
linked table in Microsoft SQL Server Management Studio Express, I get now the follow error:
---------------------------
No row was updated.
The data in row 12 was not committed
Error source: .Net SqlClient Data provider.
Error Message: Transaction context in use by another session.
Correct the errors an retry or press ESC to cancel the change(s).
---------------------------------
All other programs are close, except MSE
thanks a lot!!!!!
Can somebody help me to make the linked tables are not read-only? What is
the problem, what did I wrong?
Thanks a lot!
View 3 Replies
View Related
May 10, 2006
I would like to store and read .doc file in a table of sql server using C#.
Can some body help me on this? my id is padam76@gmail.com.
Thanks & Regard,Padam Kumar Tripathi
View 1 Replies
View Related
Sep 21, 2006
Hello
I'm working on a package which loops through each xml file in a folder.
The name of each xml file is put in variable.
The format of the filename is something like "part1_part2_part3.xml"
I need to store the 3 parts in three different columns of table A
The content of the xml file needs to be manipulated ("." needs to be replaced with ",", ....)and put in serveral columns in tableB
It's not clear to me yet how to start this but my main concern is read the three parts of the filename. I don't find any task in SSIS which could help me with that.
Could someone give me some pointers?
Many thanks!
Worf
View 3 Replies
View Related
Feb 15, 2007
Hi,
My Issue is that, I have to create a package which should read from multiple table from a RDBMS Source.
Right now I have different Source adapters for each table. I want to reduce the number of source adapters.
Can I
1) Create a connection manager and set the connection string from a variable. Set the variable from a script task. Put both of these into for loop container (no of tables).
Issues
a) Most of the table has same schema, but few have different, so all tables which has same schema will work.
For different schema anyway I have to create different data source.
b) Will Destination column mapping work.
If any one has already worked on it let me know.
Thanks
Dharmbir
View 1 Replies
View Related
Jul 14, 2007
Is there a way to get the last read/write time of a table?
I want to have a few tables, but only allow them to exist if they have been used in the last 30 days. I want to set up a "purge" job to clear out any tables that have not been used in 30 days.
View 4 Replies
View Related
Feb 26, 2008
Declare @cmd varchar(255)
select @cmd = 'bcp "select * from mytable" queryout c:cptest.txt -Uasdfasdfasdf -Pasdfasdf'
when i run this it says "The command(s) completed successfully." but i don't see that file anywhere at all. why is that? is this the right way to do? please help.
View 1 Replies
View Related
Nov 25, 2001
In a stored procedure, I am trying to create a table and then read it from within that SP or from another one (nestsed). When I run the below code (simplified version of my real SP), no records are returned even though I know that there is data. The table is created and records are inserted, I just cannot read the records from the SP or one that calls it with an EXEC.
Any ideas? My code is listed below. (When I get this to work, I plan to convert the code to manipulate a temporaty table).
Alter Procedure spWod_rptWoStatusSummary_9
As
BEGIN
CREATE TABLE tblStatusSummary (TckStaffCd_F Char(3), RecType Char(20))
INSERT INTO tblStatusSummary
SELECT TckStaffCd_F, RecType
END
BEGIN
Select * from tblStatusSummary
end
View 1 Replies
View Related
Aug 20, 2003
How do I read the Tables description into ADODB.Recordset and then recreate the Tables+description into a new database from the ADODB.Recordset.
View 1 Replies
View Related
Apr 10, 2008
Hello,
Any help here much appreciated.
I am using sql server 2000 to perform address cleansing. there is a point in my scripting when a table i pass values to becomes read/write.
i suspect this is when i run a cursor through the table.
Is anyone able to confirm for me whether running a cursor changes a table's properties?
Many thanks.
Tim
Ps as the table seems to be read/write it is harder to tell if NULLs are in the table and this is messing with joins I have further down the track.
View 3 Replies
View Related