Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

Saturday, March 24, 2012

Tag not well formed?

I keep getting a "Parser Error Message:The server tag is not well formed" message for this. Can anyone help me understand why?

<asp:SqlDataSource ID="ctrlDataSource" runat="server"
ProviderName="System.Data.OleDb"
ConnectionString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("Database\TestDB.mdb")
Set DbConnection = Server.CreateObject("ADODB.Connection")
DbConnection.Open ConnectionString
SelectCommand="SELECT * FROM [Testtable] WHERE ID=@dotnet.itags.org.id" >

Is it the &? or Server.MapPath(@."Database\TestDB.mdb") ?


I don't think it is the &. I've seen it in sample code that uses Server.MapPath as part of the connectionstring. However, if not for the &, how would I make the Server.MapPath part of ConnectionString?

g2000:

or Server.MapPath(@."Database\TestDB.mdb") ?


I'm not sure what you mean...that there should be @. ?


doesn't it need the closing /

... /> instead of ...>


Actually, I close the tag later on, after SelectParameters. More completely, it looks like this:

<asp:SqlDataSource ID="ctrlDataSource" runat="server"
ProviderName="System.Data.OleDb"
ConnectionString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("Database\TestDB.mdb")
Set DbConnection = Server.CreateObject("ADODB.Connection")
DbConnection.Open ConnectionString
SelectCommand="SELECT * FROM [Testtable] WHERE ID=@.id"
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" />
</SelectParameters
</asp:sqldatasource


have you tried hard-coding the conn string, as a test?


Yes. I used

<asp:SqlDataSource ID="ctrlDataSource" runat="server"
ProviderName="System.Data.OleDb"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=e:\ectserver\abcuser\DataBase\Testdb.mdb"
SelectCommand="SELECT * FROM [Testtable] WHERE ID=@.id" >

Now that is a bogus path, because I don't know the real one (this is not my server). However, the error message I get back is "is not a valid path," which is what I wouldexpect since it's bogus. It no longer complains"tag is not well formed." So why is the hard-coded tag well-formed while the other one isn't? I think there must be something about the syntax of my original <asp:SqlDataSource> ?


I don't think SqlDataSource has properties like

Set DbConnection = Server.CreateObject("ADODB.Connection")
DbConnection.Open ConnectionString

I am just beginning with ASP.NET but i think you would have to use <%= Server.MapPath("Database\TestDB.mdb") %>


I don't think you can concatenate a connection string within the SqlDataSource tag.

Try creating a connection string and assigning it to the data source programmatically in your code-behind page.



Ted C:

Try creating a connection string and assigning it to the data source programmatically in your code-behind page.

OK. How would I do this?


While lookking for the exact answer to your question, I found how to set up your connection string in your Web.config file. You'd have the following as part of the Web.config...

<connectionStrings>
<add name="SqlConnectionString"
connectionString="Data Source=localhost\band;Initial Catalog=Players;
Persist Security Info=True;User ID=band;Password=letmein"
providerName="System.Data.SqlClient"/>
</connectionStrings>

... and then your SqlDataSource tag would look something like...

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SqlConnectionString %>"
SelectCommand="SELECT [PlayerName], [PlayerManufacturerID] FROM [Player]">
</asp:SqlDataSource>

EDIT: Except I don't know if that solves your problem of dynamically building the connection string...

More searching...


OK, ConnectionString is a property of the SqlDataSource object, so you first create a string variable and use it to build your connection string dynamically...

string myConnString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("Database\TestDB.mdb");

...then you assign that string to the SqlDataSource's ConnectionString property...

SqlDataSource1.ConnectionString = myConnString;

You might even be able to do it in one line in the code-behind page.

SqlDataSource1.ConnectionString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("Database\TestDB.mdb");

That's in C#, of course. You'd need to translate it into VB, if that's what you're using.


Ted C:

OK, ConnectionString is a property of the SqlDataSource object, so you first create a string variable and use it to build your connection string dynamically...

string myConnString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("Database\TestDB.mdb");

...then you assign that string to the SqlDataSource's ConnectionString property...

SqlDataSource1.ConnectionString = myConnString;

I tried that a little earlier, when you first suggested that maybe I could not concatenate within the tag. I tried

<%

string cstr = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("TestDB.mdb");

SqlDataSource.ConnectionString = cstr;

%>

I also tried single-line. But I kept getting back the error "CS0120:An object reference is required for the nonstatic field, method, orproperty 'System.Web.UI.WebControls.SqlDataSource.ConnectionString.get'" which is why I wound up asking how do I do it...I am not familiar with this error?


Although OLEDB can be used with SQLDATASOURCE, however why not use AccessDataSource which is built for this purpose. Actually it inherits from sqldatasource.

An example

<asp:AccessDataSource id="InvoiceAccessDataSource" DataFile="~/App_Data/Northwind.mdb" runat="server" SelectCommand="[Employee Sales By Country]" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:Parameter Name="Beginning Date" Type="DateTime" defaultValue="1/1/1997" /> <asp:Parameter Name="Ending Date" Type="DateTime" defaultValue="1/31/1997" /> </SelectParameters></asp:AccessDataSource><asp:GridView id="InvoiceGridView" runat="server" AutoGenerateColumns="True" DataSourceid="InvoiceAccessDataSource" />
http://msdn2.microsoft.com/en-us/library/8e5545e1.aspx
Should you wish to continue using Sql datasource then here is how to do it.
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html > <head runat="server"> <title>ASP.NET Example</title></head><body> <form id="form1" runat="server"> <asp:SqlDataSource id="SqlDataSource1" runat="server" DataSourceMode="DataReader" ConnectionString="<%$ ConnectionStrings:MyNorthwind%>" SelectCommand="SELECT LastName FROM Employees"> </asp:SqlDataSource> <asp:ListBox id="ListBox1" runat="server" DataTextField="LastName" DataSourceID="SqlDataSource1"> </asp:ListBox> </form> </body></html>
http://msdn2.microsoft.com/en-us/library/dz12d98w(vs.80).aspx
 
Hope that helps, please ping with any questions

Thursday, March 22, 2012

tags in textbox

Hi Im using ASP.NET and C#

and I want to insert tags in a text box but its giving me an error that its a dangerous attempt so can I set any validation to allow that

Hi,

you can use theValidateRequest property to turn that on or off. Be mindfull that this opens your pages for potential hacks though so use with care.

You can also take a look at theAnti Cross Site Scripting library.

Grz, Kris.

taking a build of asp.net 2005 application.

hai

please help me. when i am trying to get a build i got this problem. here i am giving that error. please if any one can resolve it respond to this.

Compilation Error

Description:An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message:CS0030: Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'

Source Error:

Line 120: public login_aspx() {Line 121: string[] dependencies;Line 122: ((Login)(this)).AppRelativeVirtualPath = "~/Login.aspx";Line 123: if ((global::ASP.login_aspx.@dotnet.itags.org.__initialized == false)) {Line 124: global::ASP.login_aspx.@dotnet.itags.org.__stringResource = this.ReadStringResource();


Source File: c:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\its\6b99b5ef\95ca6e32\App_Web_login.aspx.cdcab7d2.b6tyqpzy.0.cs Line: 122

Hi and Welcome to ASP.NET Forum!

this in your context refers to System.Web.UI.Page and you are trying to cast it to Login (which of type System.Web.UI.WebControls.Login) which cannot be done. What you are trying to do? Are you trying to get a reference to the page?

Thanks

Taking a value from a dataset

I trying to get a single values from a dataset however I keep getting the following error please help

 Function get_poll_questions() As System.Data.DataSet

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=db\database.mdb"
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT top 1 * FROM tbl_poll_questions ORDER BY pol_question, rnd(pol_ID)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

strTESTING = DataSet.Tables("tbl_poll_questions").Rows(0)("pol_question").ToString()

return strTesting

End Function

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 116:
Line 117:
Line 118: strTESTING = DataSet.Tables("tbl_poll_questions").Rows(0)("pol_question").ToString()
Line 119:
Line 120: return strTesting

Many thanks in advanceMake sure that the SQL has returned any data. Also make sure that pol_question is the correct name of the column.
Also, I havent seen it done like this:

strTESTING = DataSet.Tables("tbl_poll_questions").Rows(0)("pol_question").ToString()

Try this instead:

strTESTING = DataSet.Tables("tbl_poll_questions").Rows(0).items("pol_question").ToString()

Also, since you are doing this:
dataAdapter.Fill(dataSet)

and not giving a table name...the table is not named "tbl_poll_questions". Rather, it is named just "table" or you could use the index of 0, like:

strTESTING = DataSet.Tables(0).Rows(0).items("pol_question").ToString()

In order to use that table name you would have to do:
dataAdapter.Fill(dataSet,"tbl_pol_questions")

MajorCats