Showing posts with label greetings. Show all posts
Showing posts with label greetings. Show all posts

Thursday, March 29, 2012

NEWBIE - Multicolumn Listbox populated from SQL statement

Greetings,

I am attempting to generate a multicolumn listbox from a SQL statement in
ASP.NET. Below is my SQL Statement:

SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]

I would like a two column list box with [PACONTNUMBER] on the left and
[PAcontname] on the right. I can do this in MS Access with no problem, but
I do not know to get my datareader info into a multicolumn listbox. I can
do one column of data just fine, but cannot add the second column.

Thank you for your help,

-DaveDeclare the listbox on the .aspx page:
<asp:ListBox runat="server" id="LB" /
Then in code-behind, add the items as you iterate through the repeater:
'Get Repeater 'Data'...
While ( Data.Read() )
LB.Items.Add(New ListItem(Data.Item("Field1") + "-" + Data.Item("Field2"), Data.Item("Field1")))
End While

Note: The above code will have [Field1-Field2] as the text field and [Field1] as the value field for each item in the SqlDataReader

"RockNRoll" wrote:

> Greetings,
> I am attempting to generate a multicolumn listbox from a SQL statement in
> ASP.NET. Below is my SQL Statement:
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no problem, but
> I do not know to get my datareader info into a multicolumn listbox. I can
> do one column of data just fine, but cannot add the second column.
> Thank you for your help,
> -Dave
>
concatenate two columns into one in your sql query

select column1 + column2 as multicolumn
from mytable

then have your datareader use "multicolumn" as your textfield. You'll probably have to do some spacing on top of this if you want the results in actual columns, but that should be easy enough.

Also there is a third party control that does multi-column listbox and some more stuff
http://easylistbox.com/demoQuickStart.aspx#easy

--Michael

"RockNRoll" <daveweber@.yahoo.com> wrote in message news:eJAoYOkeEHA.3916@.TK2MSFTNGP11.phx.gbl...
> Greetings,
>
> I am attempting to generate a multicolumn listbox from a SQL statement in
> ASP.NET. Below is my SQL Statement:
>
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
>
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no problem, but
> I do not know to get my datareader info into a multicolumn listbox. I can
> do one column of data just fine, but cannot add the second column.
>
> Thank you for your help,
>
> -Dave
>

NEWBIE - Multicolumn Listbox populated from SQL statement

Greetings,
I am attempting to generate a multicolumn listbox from a SQL statement in
ASP.NET. Below is my SQL Statement:
SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
I would like a two column list box with [PACONTNUMBER] on the left and
[PAcontname] on the right. I can do this in MS Access with no problem, but
I do not know to get my datareader info into a multicolumn listbox. I can
do one column of data just fine, but cannot add the second column.
Thank you for your help,
-DaveDeclare the listbox on the .aspx page:
<asp:ListBox runat="server" id="LB" />
Then in code-behind, add the items as you iterate through the repeater:
'Get Repeater 'Data'...
While ( Data.Read() )
LB.Items.Add(New ListItem(Data.Item("Field1") + "-" + Data.Item("Field2"), D
ata.Item("Field1")))
End While
Note: The above code will have [Field1-Field2] as the text field and [Field1
] as the value field for each item in the SqlDataReader
"RockNRoll" wrote:

> Greetings,
> I am attempting to generate a multicolumn listbox from a SQL statement in
> ASP.NET. Below is my SQL Statement:
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no problem, but
> I do not know to get my datareader info into a multicolumn listbox. I can
> do one column of data just fine, but cannot add the second column.
> Thank you for your help,
> -Dave
>
>
concatenate two columns into one in your sql query
select column1 + column2 as multicolumn
from mytable
then have your datareader use "multicolumn" as your textfield. You'll =
probably have to do some spacing on top of this if you want the results =
in actual columns, but that should be easy enough.
Also there is a third party control that does multi-column listbox and =
some more stuff
http://easylistbox.com/demoQuickStart.aspx#easy
--Michael
"RockNRoll" <daveweber@.yahoo.com> wrote in message =
news:eJAoYOkeEHA.3916@.TK2MSFTNGP11.phx.gbl...
> Greetings,
>=20
> I am attempting to generate a multicolumn listbox from a SQL statement =
in
> ASP.NET. Below is my SQL Statement:
>=20
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
>=20
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no =
problem, but
> I do not know to get my datareader info into a multicolumn listbox. I =
can
> do one column of data just fine, but cannot add the second column.
>=20
> Thank you for your help,
>=20
> -Dave
>=20
>

Friday, March 16, 2012

Newbie needs help

Greetings,

I have been developing with ASP 3.0 and VB6 for the past few years and I decided it was finally time to learn .NET. I have recently purchased VB.NET and I am running on a win2k adv server box using Access 2002 as a back end (I am working on aquiring SQL Server). I am attempting to test my first code in ASP.NET but I am having difficulties. I am hoping somebody may be able to point me in the correct direction. The code I am using is posted below.


<HTML>
<HEAD>
<title>WebForm1</title>
<script language="vb" runat="server">
Sub Page_OnLoad(sender as Object, e as EventArgs)
Response.Write("called")
Dim strConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\inetpub\wwwroot\webapp1\db1.mdb;"

Dim objConn as New OleDbConnection(strConnString)
Dim strSQL as String = "SELECT * FROM Names"
Dim objCmd as new OleDbCommand(strSQL, objConn)

MyDataGrid.DataSource = objCmd.ExecuteReader
MyDataGrid.DataBind()
End Sub

Sub MyButton_OnClick(Sender as Object, e as EventArgs)
Response.Write("called")
End Sub
</script>
</HEAD>
<body>
<form name="frmTest" runat="server">
<asp:Button ID="MyButton" Runat="server" Text="Click Me" />
<asp:DataGrid ID="MyDataGrid" Runat="server" BorderColor=#ff00ff />
</form>
</body>
</HTML>

For some reason when I view this .aspx page the datagrid doesn't show up and neither does the data access portion. Coming from an ASP 3.0 background my first instinct was to place the "response.write" command in the page_load sub to see if that sub was being called correctly. None of the above shows up on the page. However, if I place a plain text box or button it shows up fine. I have searched the forums here and found a few posts that had a similar problem, so I ran the aspnet_regiis -i from the cmd prompt and it installed correctly, but it didn't help my problems any. I also made sure that IIS has this set up as an application. Being new to .NET I am not sure where to go from here and would appreciate any feedback on how to fix this issue.

Regards,
Coreywell the first thin I see is that you are using Page_OnLoad which is incorrect, it is Page_Load. Also you have not opened the connection so just add this before you define your sql string

objConn.Open()

then after you you bind the data, make sure you close the connection using

objConn.Close()

That should solve the problem
Hi,

first off all: response.write was used a lot in classic asp but in asp.net it's nicer to use trace.write (or trace.warn). Make sure that tracing is enabled for the page.

You're probably using webmatrix as a tool so it's better to check out theguided tour first.

Grz, Kris.
Thanks for the replies. I began to experiment with the code behind files and finally figured out that my problem was with the name of my db table name. It was a reserved word and when I surrounded it by "[ ]" it began working properly.

Regards,
Corey

Newbie needs VWDE deployment help. Need to import database from local machine to shared ho

Greetings,

I'm trying to migrate a website on shared hosting (Godaddy) from Classic ASP to ASP.Net. Having one major issue.

I have figured out that when you create roles and users in VWDE, it creates a database(aspnetdb.mdf) in the App_Data directory and that is where the informaion is stored. On my shared hosting through Godaddy, you can select "schema features" that sets up your SQL database with all the tables the same (or at least very similar) to the aspnetdb database.

I've been wading through countless posts regarding issues with Godaddy / ASP,Net. Most of the posts are guys having problems with getting a personal starter website running. The resolution involves an .sql file. The the t-SQL statements are cut and pasted into an online tool that godaddy has on their site. This then populates the database. How that file gets created I don't know.

Long story short (oops, too late for that!), how can I export my aspnetdb.mdf data into an .sql file that I can then cut and paste into godaddy's online tool?

Important point -- You cannot connect remotely to the SQL server with godaddy so that option's out.

Please advise,

Thanks

Dave.

So are you wanting to generate sql scripts to duplicate the database you have created locally on Go Daddy's server correct? If you are using enterprise manager you should be able to generate the scripts with a right click option. When I setup membership and roles for a 2.0 site I utilized a free tool I found online somewhere - this tool allowed me to connect directly to my hosting company's sql server and modifiy users directly, but like you said you can't do that with GoDaddy.

When I'm in SQL Server Management Studio Exprees, I can attach to the aspnetdb file and see the little bit of data I have in there. When I right click on a table and go "Script Table as >" ! "Insert to >" | "File..." it gives me this:

INSERT INTO [C:\DOCUMENTS AND SETTINGS\COMPAQ_OWNER\MY DOCUMENTS\VISUAL STUDIO 2005\KOKOFEES\APP_DATA\ASPNETDB.MDF].[dbo].[aspnet_Users]
([ApplicationId]
,[UserId]
,[UserName]
,[LoweredUserName]
,[MobileAlias]
,[IsAnonymous]
,[LastActivityDate])
VALUES
(<ApplicationId, uniqueidentifier,>
,<UserId, uniqueidentifier,>
,<UserName, nvarchar(256),>
,<LoweredUserName, nvarchar(256),>
,<MobileAlias, nvarchar(16),>
,<IsAnonymous, bit,>
,<LastActivityDate, datetime,>)

There are 3 rows of data in this table, What am I doing wrong?


Hmm... not really sure. Have you researched the bcp utility? I'm not sure if it's included with the Express edition. Also you can google Bulk Insert and you should get some ideas. Here's a link to a solution in T-SQL that inserts data into a table from text files.

http://www.sqlteam.com/item.asp?ItemID=3207