Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Saturday, March 31, 2012

The best file format to import/export data into sql database through asp.net application

Hi,

We are developing a SQL server based asp.net application. As part of
requirement we should allow users import/export some relational data through
web user interface. We are investigation which file format would be the most
efficient format to import export relational data.

So far we came up with two options: XML and Access MDB files and we prefer
MDB files.

Is there any better file format for import/export data?

Any help would be appreciated,
MaxThe format is not part of the requirements ? What is the exact purpose ?

IMO users are more used to spreadsheet files rather than to xml or even
Access files. Of course it depends if the overall goal is to import/export
data to automated systems or if this is to allows users to handle those
files by themselves in a familiar tool...

My personal default preference would be likely Excel files but your berst
bet is liekly to ask them what they intend to do with those files...

--
Patrice

"Max2006" <alanalan1@dotnet.itags.org.newsgroup.nospama crit dans le message de news:
OtaUPQpCIHA.464@dotnet.itags.org.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hi,
>
We are developing a SQL server based asp.net application. As part of
requirement we should allow users import/export some relational data
through web user interface. We are investigation which file format would
be the most efficient format to import export relational data.
>
So far we came up with two options: XML and Access MDB files and we prefer
MDB files.
>
Is there any better file format for import/export data?
>
Any help would be appreciated,
Max
>
>
>


CSV is what I would pick.

"Max2006" <alanalan1@dotnet.itags.org.newsgroup.nospamwrote in message
news:OtaUPQpCIHA.464@dotnet.itags.org.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hi,
>
We are developing a SQL server based asp.net application. As part of
requirement we should allow users import/export some relational data
through web user interface. We are investigation which file format would
be the most efficient format to import export relational data.
>
So far we came up with two options: XML and Access MDB files and we prefer
MDB files.
>
Is there any better file format for import/export data?
>
Any help would be appreciated,
Max
>
>
>


I see nothing wrong with MDB as asp.net has a data provider for it. You can
read it directly into SQL Server using dataset, I would think.

David
"Max2006" <alanalan1@dotnet.itags.org.newsgroup.nospamwrote in message
news:OtaUPQpCIHA.464@dotnet.itags.org.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hi,
>
We are developing a SQL server based asp.net application. As part of
requirement we should allow users import/export some relational data
through web user interface. We are investigation which file format would
be the most efficient format to import export relational data.
>
So far we came up with two options: XML and Access MDB files and we prefer
MDB files.
>
Is there any better file format for import/export data?
>
Any help would be appreciated,
Max
>
>
>


CSV (Comma Separated Values) is generally considered to be the most
platform-agnostic file format.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"Max2006" wrote:

Quote:

Originally Posted by

Hi,
>
We are developing a SQL server based asp.net application. As part of
requirement we should allow users import/export some relational data through
web user interface. We are investigation which file format would be the most
efficient format to import export relational data.
>
So far we came up with two options: XML and Access MDB files and we prefer
MDB files.
>
Is there any better file format for import/export data?
>
Any help would be appreciated,
Max
>
>
>
>

The best way for OOP

Hi, I'm creating an application with a drop down menu that is populated by a database. The application has 4 other sections which also use the same drop down menu, however each of the 5 sections populate the drop down menu based on the section the user is in.

Currently I am using a single code behind file that queries the db and populates the drop down. I have all 4 sections using the same code behind file. Each section sends the code behind a parameter which allows the method to run the specific section query.

My questions are:

1. Is this the right way to do this?
2. Or should I create a class that all sections use? If I should create a class, what is the code behinds purpose, just to call the class?

I guess I'm kind of confused, it seems as though the code behind really is a class, I can place methods inside it and reuse them whereever I want. I would really like to be sure that I'm following OOP and doing this the correct way.

Thanks, DanBUMP, please help. Any takers? Is this a dumb question?
It's not a dumb question. It's a very good one.

You ask whether it is the "right" way to do it. In terms of OOP, then I'd suggest it's not the right way. The way you've described it, you have to pass in a parameter to your method in order for your code-behind to know how to populate the drop-down list. I'm guessing it's like this (using pseudo-code):

Namespace MyApp

Public Class Sections

Public Function GetList( ByVal strSection As String ) As ArrayList

Dim dstToReturn As New DataSet()

Select Case strSection

Case "homepage":
dstToReturn = SQLquery( "SELECT titles FROM Pages WHERE section='home'" )
' for the home page, we also add in a link to the sitemap and search pages
dstToReturn.Rows.Add( "sitemap" ... )
dstToReturn.Rows.Add( "seach" ... )

Case "help page":
dstToReturn = SQLquery( "SELECT titles FROM Pages WHERE section='help'" )
' for this page, we also add in a link to other resources
dstToReturn.Rows.Add( "forums" ... )
dstToReturn.Rows.Add( "other resources" ... )

Case "products page":
dstToReturn = SQLquery( "SELECT titles FROM Pages WHERE section='products'" )

Case "order page":
dstToReturn = SQLquery( "SELECT titles FROM Pages WHERE section='purchase'" )

End Select

Return dstToReturn

End Function
End Class
End Namespace

If I'm correct, then it is poor OOP design because it requires that you know,in advance, all of the ways in which your function might be used. If you add another section to your site, then you'd have to change your function.

This is bad because it violates thevery fundamental Open Closed Principle. To get an understanding of this and other principles of OOP, start atthis page. Follow its links andsearch for any terms you don't understand.

There are many principles and ideas about OOP, so I wouldn't recommend getting too concerned about finding the "right way". Get the gist of the Open Closed Principle, and then just start coding. You'll soon stub your toe in places where you find you should have done something differently, and you'll remember next time.

As a kind of litmus test though ... if you're using If/Then or Select Case statements, then you're probably not creating clean OOP code. Such loops are poor for performance and mean you are looking for thingsknown in advance.

Is that any help?
Dan, what you're doing is ok providing all sections are in the same page. if not then a seperate class may be useful. Also are you using a stored proc to return the data or dynamic sql in the code? if your rdbms supports sprocs then i would use one to improve performance (and to make maintenance easier).

To clear up your confusion, the code behind file IS a class. It inherits from the page class. Your aspx file in turn also compiles to a class that inherits from your code behind class. Cool hey!

Jon.

Wednesday, March 28, 2012

The big hole in .Net - Reporting

OK - So you've written a killer invoicing application in ASP.Net using SQL Server as a data store.

Your database works a treat, the user interface looks great on screen and then your customer spoils it all by asking - "how do I print an invoice" ?

Mmmm - never thought about that !

Well, I'm just a dumb developer who has been writing Windows app's for 10 years and is used to easily creating all the reports once the main application is working.

What is Microsoft's excuse ?

Why is there no reporting capability for ASP.Net ?

Their "partners" who have just such a product to fill the gap, must be raking it in - especially as they all provide a license on a per server basis !

I'd like to know how other developers are currently reporting and printing from their ASP.Net applications and if any improvements are planned for the next version.

Steve.Crystal Reports is included with VS.NET, if you have that. That's the reporting solution. You can also use Microsoft's SQL Server Reporting Services, a free add-on to SQL Server 2000.

Or you could create a PDF file from the server with it. Or you could just have them print the Web page (admittedly this is less than desireable).

Lots of options. Any of these work?
Don
Well, actually MS just release SQL Reporting Services that is based on the .NET framework, and can be expanded using .NET.
Don,

Thanks for the suggestions.

Some time ago, I wasted several hours and could not even get a connection to SQL Server from Crystal Reports. I wasted many more hours trying other things with it. Some of my applications ship to customers to run on their intranets and I would not want them to go anywhere near Crystal Reports. There is also very little support - unless you flash the cash of course !

I have been looking at PDF writers for over 12 months in the hope that one will appear where you do not need a license for each server. I have still not found any.

I am not familiar with the SQL Server Reporting add on - can you point me in the right direction as I would be very interested to find out more.

Matt,

Sounds good - where can I find out more.

Steve.
Steve,

i'm using ActiveReports.NET to generate Reports as HTML Pages, Excel Sheets and PDF's within my web site. It works well and it is easy to use. You can download a trial version at

Data Dynamics

Tom
Thanks Tom,

I've been considering Active Reports. Would I be able to design an invoice report and ensure that it prints out exactly as required - regardless of the users browser or screen resolution ?

Steve.
I use ActiveReports. Very easy, extendible, and affordable.
You have several options, but usually you would generate PDFs,
which do print exactly as required, regardless of browser, etc.
You can find SQL Reporting Services at http://www.microsoft.com/sql/reporting
I wrote a small vb.net windows app which is using the crystal report components integreated in VS.net. I had to create a setup project and put in the licence keys. Now it works perfect on the machine I installed the app.

So I think it's very easy to use Crystal Reports. You can do the same with webprojects and generate pdf's there.

Just an idea ...
Many of my clients use MSDE. When asked if MSDE is supported - the FAQ from SQL Server Reporting states...

"Although Reporting Services can use data from MSDE databases, the Report Server Database cannot be stored in an instance of MSDE."

I'm not too sure if that's a Yes or a No ?

Can anyone expand on that ?

Thanks for the other suggestions - I'm looking into those too.

Steve.
I might be missing something here, and I'd like one of the ActiveReports users to correct me if I'm wrong, but...

I use Crystal Reports. I'm a big fan of the product froma development point-of-view, but have always hated it from a deployment perspective.

That said, at $9,000 + for each per-site license of the professional edition of Active Reports, what exactly am I getting that the 'free', out-of-the-box .net edition of CR doesn't already give me? With a few lines of code, I can export to pdf. I can do HTML reports. I can export effortlessly to word and excel and RTF.

Trust me, I'm not an avid CR defender; I'm really just curious here...
Well, I would start by reading the license for the "free" Crystal Reports edition.
Note that I'm not a reader of "legalese" either, but people I work with do read it,
and I can assure you many places pay a heck of a lot more than $9000 for CR.
Its also a question of you get what you pay for -- CR just sucks most of the time.
Well, we'll have to agree to disagree on that last point. I think that there is real value in CR< though the support sucks.

But I've implemented numerous site with the CR that comes bundled with enterprise edition. And I didn't see anything that suggested to me that Active Reports offers anything above and beyond. What are the features that it offers that make it a solid alternative to CR?
By the sounds of it - I think that licensing seems to be the key issue as both CR and Active Reports are very powerful products.

The problem I have with CR (other than not being able to get it to work) is that they have given very little in the free version for developers requiring a runtime-free product. They have "dangled a carrot" by getting it bundled with Visual Studio.Net - but it's really not worth taking a bite.

A $9,000 licence fee may be acceptable for large projects, but unfortunately, I rely on selling ASP.Net applications to smaller companies - at a lot less than $9K a go !

Looks like Active Reports is favourite for me.

By the way - don't Microsoft own Crystal anyway ? - that would explain a lot.

Steve.
Well that is my point. For the Professional Version of Active Reports, at least according to the website, you'll be paying that $9,000 per site liscensing fee. And given that, I wonder just what it has and does that Crystal doesn't...

Monday, March 26, 2012

The connection name ConnectionString was not found in the applications configuration or th

Hi All, I need help. I am developing a very simple ASP.NET Application that retreived some information from an Oracle Database.

The application was working fine, but suddenly it stopped working with the following exception:

"The connection name 'ConnectionString' was not found in the applications configuration or the connection string is empty."

Furthermore, I had backups of the application on my hard drive, and all suddenly stopped working with the same exception. I beieve it is a general Configuration issue ... because all the connections are failing with the same exception.

Following is the excepton, and the line where the exception is given:

Line 55:
Line 56:
Line 57: <asp:SqlDataSource ID="SqlDataSource42" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString42%>"
Line 58: ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
Line 59: SelectCommand="Select * from TBORDER_ACTION where customer_id = 'XYZ'">

And again the exception is "The connection name 'ConnectionString' was not found in the applications configuration or the connection string is empty."

Following is my Web.config:

<?xmlversion="1.0"?><!--

Note: As an alternative to hand editing this file you can use the

web admin tool to configure settings for your application. Use

the Website->Asp.Net Configuration option in Visual Studio.

A full list of settings and comments can be found in

machine.config.comments usually located in

\Windows\Microsoft.Net\Framework\v2.x\Config

-->

<configurationxmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<connectionStrings>

<addname="ConnectionString42"connectionString="Data Source=DatabaseInstance;User ID=Username42;Password=Password42;Unicode=True"providerName="System.Data.OracleClient" />

<addname="ConnectionString42m"connectionString="Data Source=DatabaseInstance;User ID=Username;Password=Password42;Unicode=True"

providerName="System.Data.OracleClient" />

</connectionStrings>

<system.web>

<!--

Set compilation debug="true" to insert debugging

symbols into the compiled page. Because this

affects performance, set this value to true only

during development.

Visual Basic options:

Set strict="true" to disallow all data type conversions

where data loss can occur.

Set explicit="true" to force declaration of all variables.

-->

<compilationdebug="true"strict="false"explicit="true"/>

<pages>

<namespaces>

<clear/>

<addnamespace="System"/>

<addnamespace="System.Data"/>

<addnamespace="System.Collections"/>

<addnamespace="System.Collections.Specialized"/>

<addnamespace="System.Configuration"/>

<addnamespace="System.Text"/>

<addnamespace="System.Text.RegularExpressions"/>

<addnamespace="System.Web"/>

<addnamespace="System.Web.Caching"/>

<addnamespace="System.Web.SessionState"/>

<addnamespace="System.Web.Security"/>

<addnamespace="System.Web.Profile"/>

<addnamespace="System.Web.UI"/>

<addnamespace="System.Web.UI.WebControls"/>

<addnamespace="System.Web.UI.WebControls.WebParts"/>

<addnamespace="System.Web.UI.HtmlControls"/>

</namespaces>

</pages>

<!--

The <authentication> section enables configuration

of the security authentication mode used by

ASP.NET to identify an incoming user.

--> <authenticationmode="Windows"/>

<!--

The <customErrors> section enables configuration

of what to do if/when an unhandled error occurs

during the execution of a request. Specifically,

it enables developers to configure html error pages

to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">

<error statusCode="403" redirect="NoAccess.htm" />

<error statusCode="404" redirect="FileNotFound.htm" />

</customErrors>

--> </system.web>

</configuration>

Please help; I have been stuck with this issue for 1 week...

You have two connections strings with the same name. Is that the problem?


No - I have 2 connection string with 2 different names.

Please advice,

Mahdi


Line 57: <asp:SqlDataSource ID="SqlDataSource42" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString42%>"
Line 58: ProviderName="<%$ ConnectionStrings:ConnectionString42.ProviderName %>"



Dear jfmccarthy,

You are number 1; You are the best. I have been trying 3 days to find an answer, explored many sites, and spent more than 30 hours but could not find the answer.

Your suggestion was correct. I want to realyyyy... thank you, and wish you much success in your life (Although I am sure you are successfull).

Thanks Thanks Thanks...Big Smile


Well thank you very muchEmbarrassed

The ConnectionString property has not been initialized

Hi, I am trying to run some code I got off from the Quickstart tutorial for connecting to an Access database. I have been attempting several different methods from several different tutorials, none of which have been successful.

Here is the code that I have used which gave me the error: "The ConnectionString property has not been initialized" The complete error message is posted below the code.


<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.SqlClient" %
<html>
<script language="VB" runat="server"
Sub Page_Load(Sender As Object, E As EventArgs)

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsString"))
MyCommand = New SqlDataAdapter("select * from Release_of_Information", MyConnection)

DS = new DataSet()
MyCommand.Fill(ds, "Release_of_Information")

MyDataGrid.DataSource=ds.Tables("Release_of_Information").DefaultView
MyDataGrid.DataBind()
End Sub

</script

Below is the complete error message.

I made a change to the web.cnfg file, as is stated below, and all that I got was even less functionality (okay, no functionality) from the webserver.

any ideas ?

The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@dotnet.itags.org. Page Language="C#" Debug="true" %
or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configurationTry adding a Trace.Write (or a response.write) to see what your application sees as the configuration string - like:
Trace.Write("Config = " & ConfigurationSettings.AppSettings("PubsString"))

see what's really happening there - - it looks like, at first glance, that it merely doesn't find a viable connection string there.
Check out this link:

http://www.connectionstrings.com/
With my code now looking like this:

<configuration>
<appSettings>
<add key="PubsString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\C:\mikep\Career_Start\Career_Start.mdb;User Id=admin;Password=;" />
</appSettings>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.SqlClient" %
<html>
<script language="VB" runat="server"
Sub Page_Load(Sender As Object, E As EventArgs)
Trace.Write("Config = " & ConfigurationSettings.AppSettings("PubsString"))
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsString"))
MyCommand = New SqlDataAdapter("select * from Release_of_Information", MyConnection)

DS = new DataSet()
MyCommand.Fill(ds, "Release_of_Information")

MyDataGrid.DataSource=ds.Tables("Release_of_Information").DefaultView
MyDataGrid.DataBind()
End Sub

</script
<body

I am still getting "The ConnectionString property has not been initialized" error message.

I will be glad if I can get beyond this...
your code in web.config looks fine to me just check that you are using the same username and password as you have specified.

Also try changing this the following line:


MyConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsString"))

TO

string ConnectionString = (string) ConfigurationSettings.AppSettings["PubsString"];
SqlConnection myConnection = new SqlConnection(ConnectionString);

The conversion of a char data type to a datetime data type resulted....

Hi,

I'm trying to insert a date time value into a SQL Server Database field of type date time using a c# web form.
I get the following error...
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated"

My SQL looks like this:


INSERT INTO tblname (fldname) VALUES ('" + DateTime.Now.ToString() + "')"

What am I doing wrong?Remove the ToString() method as that is changing the DateTime type to a string (or Char type) ...at least thats what it looks like.
Nope sorry to say that didn't work.

My C# now looks like


SqlConnection myConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["eTeam_ConnectionString"].ToString());
string mySQL = "INSERT INTO tblname (datestamp) VALUES ('" + DateTime.Now + "')";
SqlCommand myCMD = new SqlCommand(mySQL, myConn);
myConn.Open();
myCMD.ExecuteNonQuery();
myConn.Close();
myCMD.Dispose();
myConn.Dispose();

And the field 'datestamp' is a SQL Server Data Type datetime

Anyone else?
You can use getDate() method of SQL server to update date.

INSERT INTO tblname (datestamp) VALUES (getDate())";
Thanks for that - definately half way to solving my problem.
What if I need to take a value from an ASP:Calendar control?
Is there a ToDate() function that will convert it as required?
You can use

Calendar1.SelectedDate.ToShortDateString())

which will convert this date into short date format.

Saturday, March 24, 2012

the DataBound event of FormView

hey

asp.net 2.0

I want to programmatically populate (with data from the database) a label
control in a FormView on a webpage.

Is it a good idea to put my logic inside the DataBound event of the
FormView?

any other suggestions?

JeffThe basic databinding pattern with a FormView is the same as with similar
Databound controls such a GridView. Assuming that all your controls (inluding
the label) have their databound field set,

private void BindData()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Users",
myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
fv1.DataSource = ds;
fv1.DataBind();
FormViewRow row = fv1.Row;

}

You could call the above method inside an if(!Page.IsPostBack) check in your
Page_Load handler.

--Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Jeff" wrote:

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
I want to programmatically populate (with data from the database) a label
control in a FormView on a webpage.
>
Is it a good idea to put my logic inside the DataBound event of the
FormView?
>
any other suggestions?
>
Jeff
>
>
>


Hey Peter!

thanks for your reply!

But I want to manipulate the data returned from the database before I set
display it in the FormView!

Instead of doing this:
<asp:TextBox ID="helloworldTextBox" runat="server" Text='<%#
Bind("helloworld") %>'>
</asp:TextBox><br />

I want to do something like this (in the code behind page):
helloworldTextBox.text = <db value>;

It's an interesting code you sent me, but I have this already configured. I
want to programmatically manipulate the data returned from db before I show
in the label control

Any suggestions?

"Peter Bromberg [C# MVP]" <pbromberg@dotnet.itags.org.yahoo.nospammin.comwrote in message
news:4C96A67E-E381-4F1C-B90B-0CA19F9C9326@dotnet.itags.org.microsoft.com...

Quote:

Originally Posted by

The basic databinding pattern with a FormView is the same as with similar
Databound controls such a GridView. Assuming that all your controls
(inluding
the label) have their databound field set,
>
private void BindData()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Users",
myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
fv1.DataSource = ds;
fv1.DataBind();
FormViewRow row = fv1.Row;
>
>
}
>
You could call the above method inside an if(!Page.IsPostBack) check in
your
Page_Load handler.
>
>
--Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"Jeff" wrote:
>

Quote:

Originally Posted by

>hey
>>
>asp.net 2.0
>>
>I want to programmatically populate (with data from the database) a label
>control in a FormView on a webpage.
>>
>Is it a good idea to put my logic inside the DataBound event of the
>FormView?
>>
>any other suggestions?
>>
>Jeff
>>
>>
>>


This is the manipulation I need done to the db data:
String str = reader.GetString(4);
lblInfo.Text = str.Replace(Environment.NewLine, "<br/>");

Maybe I instead could do this data manipulation directly in the stored
procedure (sql server 2005) which returns the datasource to the FormView??

"Peter Bromberg [C# MVP]" <pbromberg@dotnet.itags.org.yahoo.nospammin.comwrote in message
news:4C96A67E-E381-4F1C-B90B-0CA19F9C9326@dotnet.itags.org.microsoft.com...

Quote:

Originally Posted by

The basic databinding pattern with a FormView is the same as with similar
Databound controls such a GridView. Assuming that all your controls
(inluding
the label) have their databound field set,
>
private void BindData()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Users",
myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
fv1.DataSource = ds;
fv1.DataBind();
FormViewRow row = fv1.Row;
>
>
}
>
You could call the above method inside an if(!Page.IsPostBack) check in
your
Page_Load handler.
>
>
--Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"Jeff" wrote:
>

Quote:

Originally Posted by

>hey
>>
>asp.net 2.0
>>
>I want to programmatically populate (with data from the database) a label
>control in a FormView on a webpage.
>>
>Is it a good idea to put my logic inside the DataBound event of the
>FormView?
>>
>any other suggestions?
>>
>Jeff
>>
>>
>>

Thursday, March 22, 2012

The extreme basics

I am very new to this web development thing and have just started to play with Frontpage 2000. I have a an Access 2000 database which I want to use in conjunction with a web front end (to be constructed in Frontpage). There is no server involved, its just a project on my home desktop computer running either XP Home or ME.

I want to be able to add, delete, amend and query the data in the database from the web page, and understand that I need to use ASPs. I have created an ASP in Frontpage which has a database region within it connected to my local database (I set up an ODBC connection and selected that when choosing the database rather than selecting the mdb directly).

Basically I am at a loss. When viewing the web page the field headings appear, but no data. I gather from reading help files, etc that this is because I need some additional software to make it all work. If anyone can give me a few pointers as to how to get this to work, please let me know.

Best regardsyou HAVE to have a server because ASP is a "server-side" technology. you need IIS or Personal Web Server to run classic ASP, and IIS or Cassini to run ASP.NET. also, if you're not using ASP.NET (which is what it sounds like) please visit a forum for classic ASP.

ASPMessageBoard
You also might want to look at the Web Matrix tutorials - we have some dataBase examples you might find useful.

HTH

JD

http://www.asp.net/webmatrix/guidedtour/section2/newconn.aspx

The first value of a dropdownlist

How can I show a value at the beginning of the dropdownlist with my
structure? This initial value isn' t in the database, for instance
'(Select)'.

<script language="VB" runat="server"
Sub Page_Load()

Dim strConnection As New
SqlConnection("Server=nou;database=market1;uid=sa;password=;")

Dim families As string = "SELECT family_Name FROM
Families;"

Dim DS1 As DataSet
Dim CommandFamilies As SqlDataAdapter

CommandFamilies = New SqlDataAdapter(families, strConnection)

DS1 = new DataSet()
CommandFamilies.Fill(DS1, "Families")

MySelect1.DataSource=
DS1.Tables("Families").DefaultView
MySelect1.DataBind()

End Sub

</script
...

<form runat="server"
<asp:dropdownlist id="MySelect1"
DataTextField="family_Name" runat="server"
class="letter1"
</asp:dropdownlist
...

--== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==--
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
--= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--not sure of the VB .net syntax, but here it is in C#

ListItem li = new ListItem();
YourDDL.Items.Add(li, 0);

put's a blank item at the beginning of your drop down list

"cesark" <cesar_casafont@.hotmail-dot-com.no-spam.invalid> wrote in message
news:400db905$1_2@.127.0.0.1...
> How can I show a value at the beginning of the dropdownlist with my
> structure? This initial value isn' t in the database, for instance
> '(Select)'.
>
> <script language="VB" runat="server">
> Sub Page_Load()
> Dim strConnection As New
> SqlConnection("Server=nou;database=market1;uid=sa;password=;")
> Dim families As string = "SELECT family_Name FROM
> Families;"
>
> Dim DS1 As DataSet
> Dim CommandFamilies As SqlDataAdapter
> CommandFamilies = New SqlDataAdapter(families, strConnection)
> DS1 = new DataSet()
> CommandFamilies.Fill(DS1, "Families")
>
> MySelect1.DataSource=
> DS1.Tables("Families").DefaultView
> MySelect1.DataBind()
>
> End Sub
> </script>
>
> ...
> <form runat="server">
> <asp:dropdownlist id="MySelect1"
> DataTextField="family_Name" runat="server"
> class="letter1">
> </asp:dropdownlist>
> ...
>
>
> --== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet
News==--
> http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
> --= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=--
I have already achieved it 8) . The right code was:

MySelect2.Items.Insert(0, "(Select a value)")
MySelect2.SelectedIndex = 0

Just before of 'MySelect2.DataBind()'

Thank you anyway :)

--== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==--
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
--= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--

Tuesday, March 13, 2012

The login failed. Login failed for user

Hi

I am trying to capture and display a user-friendly message when my database/server is offline

In order to do the above task, I have taken my database offline and put in the following code to log and show an error has occurred.

PLEASE bear in mind the database is offline and that's what I am trying to test for

C# for RequestDetails.aspx.cs

using System.IO;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

try

{

Console.WriteLine("Executing the try statement.");

//throw new SqlException();

}

catch ( System.Data.SqlClient.SqlException test)

{

Console.WriteLine("{0} Caught exception #1.", test);

Exception objErr = Server.GetLastError().GetBaseException();

//string err = "Error Caught in Application_Error event\n" +

// "Error in: " + Request.Url.ToString() +

// "\nError Message:" + objErr.Message.ToString() +

// "\nStack Trace:" + objErr.StackTrace.ToString();

//EventLog.WriteEntry("Sample_WebApp", err, EventLogEntryType.Error);

////Tools.Log("sadsadsadas", err);

Response.Write("error" + test.Message +"<br>");

Tools.Log("log test ", test); //Logs error

Tools.SendEmail("Email test ", test); /Emails Error

}

}

When I view the page I get

Exception Details:System.Data.SqlClient.SqlException: Cannot open database "CRM" requested by the login. The login failed.
Login failed for user 'ABCDXXXSYSTEMS\ysmith'.

Can anyone tell me how to trap and action database/server offline errors please? I know I am missing a big part of a puzzle

Thanks in advance

Try the following:

protectedvoid Page_Load(object sender,EventArgs e)

{

try

{

SqlConnection Cn =newSqlConnection("connection string here");

Cn.Open();

}

catch (SqlException Ex)

{

Response.Write (

"Database is unavailable.");

}

}


What I would like to do is

publicvoid Page_Error(object sender,EventArgs e)

{

Exception objError = Server.GetLastError().GetBaseException();string strError ="<b>Error Has Been Caught in Page_Error event</b><hr><br>" +"<br><b>Error in: </b>" + Request.Url.ToString() +"<br><b>Error Message: </b>" + objError.Message.ToString() +"<br><b>Stack Trace:</b><br>" +

objError.StackTrace.ToString();

Session["ErrorMessage"] ="Cannot open CRM";

Server.ClearError();

Response.Redirect("error.aspx?ErrorMessage" + Session["ErrorMessage"].ToString());

}

in the error page display the Session["ErrorMessage"]

protectedvoid Page_Load(object sender,EventArgs e)

{

ErrorLabel.Text = Session["ErrorMessage"].ToString();}}

}

But I get error System.NullReferenceException: Object reference not set to an instance of an object.

at line:

ErrorLabel.Text = Session["ErrorMessage"].ToString();}}

thanks in advance


Try to check if session isnt null before your set the text of the ErrorLabel control.

maybe when your page loads, there isnt any error, meanwhile you are identifying the session in the page_error which didnt get executed.

protectedvoid Page_Load(object sender,EventArgs e)

{

if(Session["ErrorMessage"] != null)

{

ErrorLabel.Text = Session["ErrorMessage"].ToString();

}

}

HC


Try opening a connection to the database which would indicate connectivity or not.

Thanks guys

I did try the suggestions without much joy. The session["ErrorMessage"] = ""

Also it would be so much easier if I could read the status code.

Thanks in advance

The memory could not be "read".

Hi,

I'm currently working on an ASP.NET application. The application is connected to an Oracle database. I have multiple drop-down-list's that contains two list items ('Yes'/'No'). I have autopostback set to true. When the user selects either 'Yes' or 'No', I immediately write the users drop-down-list selection to the database. On my ASP.NET page, I have lots of these drop-down-lists for specific records. When I use these drop-down-lists slowly, everything works fine. When I start to make my selections more quickly, I receive the following error: 'The instruction at "0x7d50a0d0" referenced memory at "0x00000018". The memory could not be "read".

Any suggestions?

bump.

Possibly a problem with your browser install? I guess the page reloads when you change the first dropdown and is still reloading when you change the second - the browser should either ignore the change in the second dropdown or abort the first reload and do the second.

At a guess i'd say there's a problem with your browser - have you tried it in another browser (IE/Firefox?) or checking for updates?

Hope that helps, Adam


How many select boxes do you have? This sounds more like a problem with the client than it does with .NET.
I'm currently using the latest version of IE. The application is on a network and is occuring on everyone's machine (IE Browser). I don't want to have to make Firefox mandatory.
The amount of drop-down-lists vary depending on the users selection. It doesn't matter how many they chose, the error still occurs.

all help is appreciated.


Can you post some code?