Problem With Easy Select And Writing To A Label
Apr 23, 2008
I'm writing my first .NET app, and have a simple page where I set up a connection to my db, query it, and write out a value. But I get this error, that doesn't give me a very good idea of what I should fix...
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 10: Dim comm As SqlCommand
Line 11: Dim reader As SqlDataReader
Line 12: Dim connectionString As String = ConfigurationManager.ConnectionStrings("IntegratedData").ConnectionString
Line 13:
Line 14: conn = New SqlConnection(connectionString)
Here's the vb.net code from my page. It seems soo simple, but I'm missing something. <%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.SqlClient" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim conn As SqlConnectionDim comm As SqlCommand
Dim reader As SqlDataReaderDim connectionString As String = ConfigurationManager.ConnectionStrings("IntegratedData").ConnectionString
conn = New SqlConnection(connectionString)
comm = New SqlCommand("Select tkinit, tklast as FullName from tEliteTimeKeep", conn)
conn.Open()
reader = comm.ExecuteReader()employeesLabel.Text = reader.Item("tklast")
reader.Close()
conn.Close()
End Sub
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="EmployeesLabel" runat="server" ></asp:Label>
</div></form>
</body>
</html>
View 5 Replies
ADVERTISEMENT
Sep 27, 2006
Hello!
I am trying
to select info from a database (MS-SQL) and show that whit a label. And don’t really
get every thing to work. So I am glad for that help I can get.
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = "data
source='XXX';User ID='XXX';Password=XXX;database='XXX'";
myConnection.Open();
SqlCommand dataCommand = new
SqlCommand();
dataCommand.Connection
= myConnection;
dataCommand.CommandText = "SELECT XXX,XXX FROM XXX";
SqlDataReader dataReader =
dataCommand.ExecuteReader();
string notis1 = dataReader;
Label1.Text = notis1;
myConnection.Close(); Any help whould be helpfoul.
View 5 Replies
View Related
Mar 30, 2006
I got the following code and I like to give the label.text a value which is selected by the query in the .commandtext line. This is off course not working but I don't have any idea how it can work. Someone suggestions??Thanks!!Partial Class ShowBonsaiProperties Inherits System.Web.UI.Page Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim sqlConnection2 As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("BonsaiDataBaseConnectionString").ToString()) Dim cmd As New System.Data.SqlClient.SqlCommand With cmd .CommandType = System.Data.CommandType.Text .CommandText = "SELECT BonsaiName FROM Bonsai WHERE BonsaID = 1" .Connection = sqlConnection2 End With sqlConnection2.Open() cmd.ExecuteNonQuery() sqlConnection2.Close() Dim BonsaiNameText As Object = .CommandText LblShowBonsaiName.Text = BonsaiName End SubEnd Class
View 13 Replies
View Related
Mar 12, 2005
Im starting to learn SQL at school !!
and would like to do something like this. !! but i just cant figure that out.
i have a table that containes all my categories in it. And as you can see i have "PARENT" and "CHILD" categories.
I would like to get something like this by using a simple SELECT statement !! is it possible...
===============
=#1 PARENT ID NAME=
===============
=#1 CHILD NAME HERE
=#2 CHILD NAME HERE
=#3 CHILD NAME HERE
===============
=#2 PARENT ID NAME=
===============
=#1 CHILD NAME HERE
=#2 CHILD NAME HERE
=#3 CHILD NAME HERE
im not trying to show this in my Query Analyser but on a Web Page by using a datagrid.
View 1 Replies
View Related
Sep 13, 2004
I have a simple SQL statement like follows:
"select * from my_table where recordDate between '01/01/2004' AND '02/01/2004'"
As it is, this only returns records that are literally between those two dates, and doesnt return records that hit right on the start date or end date. What is the SQL command to make the between statement grab records inclusively, instead of exclusively as it is doing it now?
View 2 Replies
View Related
Dec 20, 2005
Hi all...I have taken a look at an archive search, and continue to research and play with mysel...errr...my select, but in the meantime...what am I missing?!?!?!
Here is my excruciatingly interesting insert statementINSERT INTO dbo.WON_MutualFundNames
SELECT UPPER(FndTickerSym), FndName
FROM L_WONDA_MUTUALS.wondb.dbo.funds
WHERE FndTickerSym LIKE '[A-Z]%[X]' /* first char is A thru Z and last char is X*/
GROUP BY FndTickerSym, FndName
Everything works just hunky-dory, EXCEPT for...two @#$(*#& rows in my database table:
FndTickerSym FndName
------------- -------------------------------
DHMBX DREYFUS YIELD MUNICIPAL BOND
dhmbx DREYFUS YIELD MUNICIPAL BOND
What has befuddled me is that when I run the SELECT by itself, only ONE of the rows is returned - - only when I combine it with the insert, I get a duplicate primary key value error (the FndTickerSym is the insert-table's primary key column).
WTF is goin' on, dudes? And perhaps more importantly, how can I get around it?
Any suggestions are welcome
well...any except "delete the duplicate row", which I am already crafting an email about to send to the offending/offensive (I assure you, they are both) group that maintains the data in this table. However, whenever I make my database idiotproof, they always invent a craftier idiot...so I must code the insert to work if such a situation presents itself again in the future.
Thoughts? Suggestions? New Cursewords?
View 2 Replies
View Related
May 28, 2008
All- I would greatly appreciate some assistance in creating a SELECT statement for table headcount in the following problem:
First, find the schema here: http://home.pacbell.net/eulimi/schema_headcount.GIF
The problem:
Given a person_id (a record in the person table), list all headcount records WHERE:1) headcount.person_id = person.person_id AND2) the headcount.act_session_id belongs to a activity (from the activity_session table) that the person is allowed to attend by virture of the person's membership in a subexpedition.
Note that:
- A person can be a member of one or more circles (via the circle_person table)- Each circle belongs to exactly one subexpedition.- A persons who is a member of a subexpedition (via one or more circles) is entitled to sign up for one or more activities (activity_sessions) associated with the subexpedition.
So, put yet another way, the SELECT command should show, for a given person_id, the list of records in headcount that includes the activities (act_session_id) that the person is entitled to join by virtue of the persons membership in the subexpedition via his circle. (Whew!)
I hope this is enough information. I think the problem would be fun if I knew what I was doing. (SQL newbie here.) I suspect I need several INNER JOINs and a compound WHERE clause.
Thanks in advance!!!
View 5 Replies
View Related
Sep 24, 2006
Is there a way I can write a query to dynamically select a database table. That is, instead of having a variable for a certain column like customerId which would be €ścustomerID = @customerID€? I want to use the variable to select the table. I assume I may have to use a stored procedure but I am unclear as to how this would be coded.
Thanks
View 1 Replies
View Related
Oct 9, 2006
i have to display some of my SQL data on a webpage, and i don't want to use the gridview and all his "friends". all i want is to display some values out of the sqlDataSource on my webpage.is it possible? and if so, then how can i do it?thanks in advance.
View 3 Replies
View Related
May 7, 2007
Hello!
Is it possible to create a row of "labels" in a multi-value parameter list?
i mean something like this:
Name, Age
JJ, 12
PP, 10
Thanks
//C
View 3 Replies
View Related
May 23, 2007
I have a Report that has a document map Label in the Report which I need to remove.
However as the report has over 50 text-boxes I am having difficulty locating it.
I have had a look at the XML but that does not seem to indicate the offending text box.
Any advice would be greatly appreciated.
Regards
JohnJames
View 1 Replies
View Related
Sep 13, 2006
Hi,Just a little question...Is it possible to link a SqlDataSource to a label without using a repeater or a formview?I just want to select one column from a single row in a single table and sending the value to a label.The code would be something like this :<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT name FROM Page WHERE idPage = 1">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="idPage" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>'></asp:Label> So, what can I add in the label properties or in the codefile to make this work if it is possible ?Or am I obliged to "hard code" it in c# with an SqlConnection, a SqlCommand and a SqlDataReader ?Thanks in advance...
View 4 Replies
View Related
Oct 16, 2006
A SQL Server 2005 stored procedure expects a parameter UserID depending upon which it retrieves the no. of records & OrderIDs corresponding to the UserID from a DB table (note that OrderID & UserID are two of the columns in the DB table). So for e.g. consider a user whose UserID=6 & the DB table has 3 records where UserID=6. In other words, there are 3 OrderID records of the user whose UserID=6, say, OrderID=8, OrderID=17 & OrderID=29. The stored procedure will finally return 2 columns - the OrderCount (which is 3 for UserID=6) & the OrderID (which will be 8, 17 & 29 for UserID=6). This is the stored procedure:ALTER PROCEDURE dbo.OrderCount @UserID intASDECLARE @OrderCount intSET @OrderCount = (SELECT COUNT(OrderID) FROM NETOrders WHERE UserID= @UserID)SELECT @OrderCount AS OrderCount, OrderIDFROMNETOrdersWHEREUserID = @UserIDIn a VB class file, I am invoking the stored procedure in a function named GetOrderCount which returns a SqlDataReader back to the calling ASPX page. I want the ASPX page to display the 3 OrderIDs of UserID=6 in a Label control. Unlike the DataBinding controls like DataList, DataGrid, Repeater controls, the Label control will not automatically loop through the recordset. So I tried to accomplish this using a For....Next loopDim i As IntegerDim sqlReader As SqlDataReaderiUserID = Request.Cookies("UserID").Value'ShopCart is the name of the class in the VB class fileboShopCart = New ShopCartsqlReader = boShopCart.GetOrderCount(iUserID)While (sqlReader.Read) If (sqlReader.GetValue(0) > 1) Then pnlLinks.Visible = True For i = 1 To sqlReader.GetValue(0) lblLinks.Text = sqlReader.GetValue(1)(i) Next i Else pnlLinks.Visible = False End IfEnd WhileBut this generates the following error:No default member found for type 'Integer'.pointing to the linelblLinks.Text = sqlReader.GetValue(1)(i)in the above shown ASPX code. Can someone please correct me & suggest how do I loop through the recordset so that I can display the records in a Label control?
View 8 Replies
View Related
Nov 17, 2006
This is my SQLDataSource for my gridview
<asp:SQLDataSource ConnectionString="<%$ ConnectionStrings:Pubs %>" id="sqlProducts" Runat="Server" SelectCommand=' "Select * from adressen INNER JOIN Adressoort ON adressen.AD_ID = Adressoort.AD_ID where " & lblsql.Text ' ></asp:SQLDataSource>
the label is something like : adressoort.AD_soort = '3' or adressoort.AD_soort = '1'
I keep on getting the error sever tag not well formed
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
Oct 23, 2007
Hi all. I have a label on my page and I want to bind it to a field in a table. The catch is that I want to bind it to the last row in the table. I think I can use the custom binding, but I don't know how to bind to the last row. Any Suggestions ?
p.s. The page is tied to an SqlDataSource that retrieves the data from the above table.
Thanks in advance.
View 5 Replies
View Related
Feb 21, 2008
hi,
i have this code it gets the records from db
i need to add the results of the datareader to a label but label control does not have a datasource property
second problem is how to comma separate the results.with array? or what please help
i need to show the results like this: record1,record2,record3Dim Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Conn").ConnectionString)
Dim strSQL As StringDim dr As SqlDataReader
Dim userID As Integer = Session("cmmLogonUserID")
strSQL = "select id,extension from musicExt"Dim cmd As New SqlCommand()cmd = New SqlCommand(strSQL, Conn)
Conn.Open()
dr = cmd.ExecuteReader()
'txtMediaFormats.Text = dr ???????
' ddlGenres.DataBind() ????????
Conn.Close()
View 6 Replies
View Related
Mar 1, 2008
Hi,
I have a sqldatasource which returns the result I want, but I need to assign it to a label or text box. Is there an easy way of doing this? I attempted it using this code:
PropertyFriendIDLabel.Text = PropUserIdSqlDataSource
Thanks
View 4 Replies
View Related
Mar 13, 2008
Here is my code. Basically what I am doing is selecting from the database based on the current user. The ReaderResults.Text label is not showing the info pulled from the database, and the ReaderError.Text label is not showing an error. I also tried putting the ReaderResults.Text label inside the loop and that didnt work. Any suggestions?
'Database ConnectionDim con As New SqlConnection("Data Source = .SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|ASPNETDB.mdf;user instance=true")Dim currentUserID
currentUserID = Context.User.Identity.Name.ToString()
Label1.Text = currentUserID
Dim selectSQL As String
selectSQL = "SELECT companyKey FROM Company WHERE UserID = ('" + currentUserID + "')"Dim cmd2 As New SqlCommand(selectSQL, con)
Dim reader As SqlDataReaderDim CompanyKey
Try
con.Open()
reader = cmd2.ExecuteReader()Do While reader.Read()
CompanyKey = reader("CompanyKey").ToString()
Loop
reader.Close()Catch err As Exception
ReaderError.Text = "Error selecting record."
ReaderError.Text &= err.Message
ReaderResults.Text = CompanyKey
Finally
con.Close()
End Try
View 1 Replies
View Related
Mar 13, 2008
The ReaderResults.Text is not returning a value. I am not sure what is going on because the table and all columns are full, Label1.Text shows the current username of the user loggedon, and no error is showing up in ReaderError.Text. Anyone have any ideas?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Database ConnectionDim con As New SqlConnection("Data Source = .SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|ASPNETDB.mdf;user instance=true")
'Job1 InfoDim currentUserID
currentUserID = Context.User.Identity.Name.ToString()
Label1.Text = currentUserID
Dim selectSQL1 As String
selectSQL1 = "SELECT companyKey FROM Company WHERE UserID = ('" + currentUserID + "')"Dim cmd1 As New SqlCommand(selectSQL1, con)
Dim reader As SqlDataReaderDim CompanyKey
'Job1 Select
Try
con.Open()
reader = cmd1.ExecuteReader()Do While reader.Read()
CompanyKey = reader("CompanyKey").ToString()
Loop
reader.Close()Catch err As Exception
ReaderError.Text = "Error selecting record."
ReaderError.Text &= err.Message
ReaderResults.Text = CompanyKey
Finally
con.Close()
End Try
View 3 Replies
View Related
Aug 17, 2007
I have a simple column chart where the x axis is a week number, and the y axis is percent of sales. There are four charts on one page, so this chart is very small. There are only two bars on the chart, and I would like to have the value of the y axis, say 7.2%, be displayed on the bar itself. Currently, I can't decipher the exact value of each bar. Does anybody know if, and how, this can be accomplished? Thank you!
View 1 Replies
View Related
Jul 9, 2007
I have a long expression that returns the value of my one label. The expression is suppose to figure out if there are three parts to the MailAddress field and return the appriopriate number of fields properly formated. The format I need to get returned from this delimited field looks like
PersonIdNumber
CO Line
Name Here
123 Address Street
City State Zip Country
Each line is followed by a semicolon which I have coded to each be replaced by a newline. The main problem is that sometimes we have a CO Line and sometimes we don't. There will be a delimeter right before the AddressStreet Line even if the CO Line does not exist, so that shouldn't be a problem.
Also, the Name Here line is not returned from my delimited MailAddress field, it is a seperate field. For some reason the label returns an error in the report. I'm assuming it is it is in the code below. If you see something wrong with the expression please let me know.
Code Snippet
=IIF(Count(Split(Fields!MailingAddress.Value, ";")) = 3, (LTrim(Replace(Replace(Choose(1, Split(Fields!MailingAddress.Value, ",")),",", " "), ";", " "))& vbcrlf & Fields!Name.Value & vbcrlf & LTrim(Choose(2, Split(Replace(Replace(Fields!MailingAddress.Value, ";", vbcrlf), ",", " "), vbcrlf)))& vbcrlf & LTrim(Choose(3, Split(Replace(Replace(Fields!MailingAddress.Value, ";", vbcrlf), ",", " "), vbcrlf)))), (Fields!Name.Value & vbcrlf & LTrim(Choose(1, Split(Replace(Replace(Fields!MailingAddress.Value, ";", vbcrlf), ",", " "), vbcrlf)))& vbcrlf & LTrim(Choose(2, Split(Replace(Replace(Fields!MailingAddress.Value, ";", vbcrlf), ",", " "), vbcrlf)))))
I'm currently using SSRS 2005...
View 12 Replies
View Related
May 9, 2008
Hi all,
In Table Detail session,
=Fields!test.Value
Will popup as numbers. 1 2 3 4 etc.
I set parameter as Value 1 = Label "First" Value 2 = Label "Second"
Is that possible to show the lable of Fields that I set in Parameter?
Advice plz.
Thank you
View 4 Replies
View Related
Feb 5, 2007
Hi, i am a newbie to reporting services.
Am trying to create a mailing label report so that it can pull out the details from the database and gets printed onto the label stickers correctly. However, no matter how i adjust the sizes of the report from the page properties, it's still not printed properly.
I have 7 label stickers on 1 mailing page, so let's say i have 13 records, that will be 2 mailing pages. Each label sticker is about 9cm width by 3.6 cm height. The gap between each label sticker is 0.2 cm
Can anyone advise me on how to go about doing it? By the way, i am using SSRS 2000.
Any help is appreciated. Thanks :)
View 1 Replies
View Related
May 6, 2008
i am once again working with mailing labels. I have designed the report in SQL Server Reporting Services to print in 3 columns with a body size of 2.625" wide by 1.00" high; a rectangle the same size which then contains a list the same size which contains the data fields. I get fairly good results when I print to one printer however, there does seem to be a bit of "creep" on the page. The problem really shows when trying to print to another network printer where when a user prints the report (labels) by the end of the page data is printing outside of the label margins. are there some properties that I'm missing that would prevent this or could this be related to printer settings?
View 4 Replies
View Related
Feb 28, 2007
I have a SQL database with 1 column in it.. it is a do not call registry for my office. I want to make a web application so our leads can go on the web and request to be put on the do not call list. problem is, if their number already exists, it gets a violation of primary key... Normal handling for this would be to do a select query based on user input, and if it exists in the database, tell them that, else do the insert query... Problem is, i cant seem to figure out how to bind the result of the select query to a textbox or label so i can compare the results to do that logic. Any ideas? This is in asp .net 2.0. Thanks! -Dan
View 5 Replies
View Related
Apr 22, 2004
i wanna know is there a way to retrieve data from the sql database and then
instead of putting it in the datagrid, can i put a specific field of data to a textbox?
i mean just a data (for example, a username where the password match the username) in a textbox.
thanks
sherlyn
View 1 Replies
View Related
Nov 12, 2005
how can i display the result of an asp:SqlDataSource into a lable control.the sqldatasource returns the count for some thing ie "select count(*) as total from tbl"please help
View 1 Replies
View Related
Jan 26, 2006
Hi,I want to run a select query and copy the result to a label. I created a SqlDataSource1, but I don't know how to go ahead.I would like to do something like:string x = SqlDataSource1.SelectCommandPlease, advice!
View 2 Replies
View Related
Jul 12, 2007
I'm designing a database that will not be that large (I would be surprised if it ever surpassed 50,000 rows across all tables), but will be accessed quite often, so I am doing my best to optimize its structure, such as doing 3NF, selecting appropriate data types, etc.
I have a few columns that will contain numeric data (such as an invoice number (from an external source) or location ID). However, one of my classes in college was about database design, and we were taught that if you won't be doing mathmatic computation on a field (such as the invoice or location fields I mentioned earlier), then you should use a string literal type (char, varchar, etc.)
Unfortunatly, the professor did not explain much as to why this should be done. From the standpoint of semantic analysis, these types of fields are probably more labels than they are numbers. However, I don't find that very convincing (or even helpful).
In short, my question is that given a column holding numeric data that isn't worked on in a mathematical sense, is it really better to mark it as a string literal than a number? Any articles or studies I can read relating to this?
I would think that comparisons would be faster with int, as well as data storage (though, as mentioned, that's not as big of a concern). Sadly, Google doesn't have many helpful resources. (Lots of stuff on char vs varchar, though.)
View 12 Replies
View Related
Sep 7, 2004
I have a table that has a column with multiple manufacturer names. Many rows are identical manufacturers. I want to create an asp page that shows only one instance of a particular manufacturer.
Basically if I have 30 entries of Manufacturer 1, 40 entries of Manufacturer 2, etc. I only want to see Manufacturer 1 and Manufacturer 2 once in the display, not as many times as it is listed in the column. Is this an ASP or SQL question?
Basically I know the beginning should look like this:
Code:
SELECT Col1, Col2
FROM dbo.tbl_Myinfo
ORDER BY Col2
But that is about the extent of where I know what to do.
I wanted to create this so I can list the manufacturers that I currently have loaded in my SQL table/ available for more detailed searching.
View 2 Replies
View Related
Dec 14, 2005
Hi!
I have these tables:
DB1
MID
IIN
Title
FullName
Address
Apt
City
Province
PostalCode
DB2
MID
Lang
Version
How can I output a text file formatted like the one below?
(05) 01046 (F 05)
Mr. Sylvain Cote
123 Sesame Street
Apt 6
Charny, BC
L8T 5G6
where
(05)-MID
01046-IIN
(F 05) - Lang
View 3 Replies
View Related
Jul 21, 2014
I have a report based on a query which requires the user to input the date range. I would like this date range to be a label in the report.
I already keying tha formula fo the data range.. Audit Fees
Report is my form
Between [Forms]![Purchase Report]![From] And [Forms]![Purchase Report]![To]
I am trying to run a report for the period "December 1 2010 to March 31 2011" However, it came out a warning message box.
"The expression is typed incorrectly or it is too complex.... try simplifying the expression by assigning parts pf the expression to variables".
View 1 Replies
View Related