Quantcast
Channel: DataSource Controls - SqlDataSource, ObjectDataSource, etc.
Viewing all 956 articles
Browse latest View live

ReportViewer and filtering

$
0
0

Hello,

 

I am try to manually; no wizard, populate a the ReportViewer control. I have been successful in doing so, by using a SQL Data Access utility class I've created. But I wanted to be able to filter result of the report as well, and as such, I explored passing in parameters and filtering based on the paramater passed in. This also works, but by placing a parameter on a field in report, if do not set; in others words leave it empty, the report itself is empty. I result are there but they are not being shown, because the filter is being applied on load; I can tell because I have other textboxes on the page that make use of the values of the report via some expressions I've written.

Is there a way to by default ignoring the filter, initially on load? I am not the best at using the ReportViewer but I am learning so please be patient with me if I ask some seemingly dumb questions. Also, is there a way to remove a filter once you no longer have use for it during runtime?


Report Viewer and Entity Framework

$
0
0

Hello,

I saw a great example online on how to populate/utilize the ReportViewer via some wizard controls, which took advantage of the Entity Framework. Here is the link to the example I am referring to http://weblogs.asp.net/rajbk/archive/2010/05/09/creating-an-asp-net-report-using-visual-studio-2010-part-1.aspx

Once you have looked at this example, could some please tell me if there Is there a way to programmatically get "NorthWindEntities" from the "ProductRepository " class without setting up a edmx object? The reason I ask is because I have searched and searched and not found too much information lending itself to this method; probably couldn't find much since I am such a noob. I like how the Linq-To-SQL is being used, but I was wondering if there was a way to accomplish this programmatically versus a wizard/designer code.

What is the usage of RowGUID under SQL Server 2005?

$
0
0

Hi All

What is the usage of Row Guid under SQL Server 2005? It seems not much information state the main purpose of it?

Regards

Alex

 

 

Local Report DataSource

$
0
0

I am trying to learn how to do Local Reports is VS 2012. I have the Client-Side reporting book and am trying to get the 1st example to work. When I try to run it I get this error: A  data source instance has not been supplied for the data source 'DataSet1'.

ReportViewer1.LocalReport.DataSources.Clear();

//prepare report data source
ReportDataSource rds = new ReportDataSource();
rds.Name = "dsAgedAR_dtAgedAR";
rds.Value = dsReport.Tables[0];
ReportViewer1.LocalReport.DataSources.Add(rds);

I don't understand the error or what to do about it. I can find DataSet1 in the XML for the Report so it must be some built-in thing but it seems like it should be overwritten by the assignment above.

DBNull Error exception

$
0
0

I am trying to store value from XSD column but getting DBNull exception error. When I tried to change the NullValue in XSD it is not allowing me to change it to Nothing . Any Suggestions how to handle this?

I have already tried IsDBNull() and it doesn't work . the datatype of column is Decimal.

break in a coloumn of gridview

$
0
0

i have a grid view like this

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" Height="154px" Width="389px">
            <Columns>
                <asp:BoundField DataField="A1" HeaderText="A1" SortExpression="A1" />
                <asp:BoundField DataField="A2" HeaderText="A2" SortExpression="A2" />
                <asp:BoundField DataField="A3" HeaderText="A3" SortExpression="A3" />
                <asp:BoundField DataField="A4" HeaderText="A4" SortExpression="A4" />
                <asp:BoundField DataField="B1" HeaderText="B1" SortExpression="B1" />
                <asp:BoundField DataField="B2" HeaderText="B2" SortExpression="B2" />
                <asp:BoundField DataField="B3" HeaderText="B3" SortExpression="B3" />
                <asp:BoundField DataField="B4" HeaderText="B4" SortExpression="B4" />
                <asp:BoundField DataField="C1" HeaderText="C1" SortExpression="C1" />
                <asp:BoundField DataField="C2" HeaderText="C2" SortExpression="C2" />
                <asp:BoundField DataField="C3" HeaderText="C3" SortExpression="C3" />
                <asp:BoundField DataField="C4" HeaderText="C4" SortExpression="C4" />
                <asp:BoundField DataField="D1" HeaderText="D1" SortExpression="D1" />
                <asp:BoundField DataField="D2" HeaderText="D2" SortExpression="D2" />
                <asp:BoundField DataField="D3" HeaderText="D3" SortExpression="D3" />
                <asp:BoundField DataField="D4" HeaderText="D4" SortExpression="D4" />
                <asp:BoundField DataField="E1" HeaderText="E1" SortExpression="E1" />
                <asp:BoundField DataField="E2" HeaderText="E2" SortExpression="E2" />
                <asp:BoundField DataField="E3" HeaderText="E3" SortExpression="E3" />
                <asp:BoundField DataField="E4" HeaderText="E4" SortExpression="E4" />
                <asp:BoundField DataField="F1" HeaderText="F1" SortExpression="F1" />
                <asp:BoundField DataField="F2" HeaderText="F2" SortExpression="F2" />
                <asp:BoundField DataField="F3" HeaderText="F3" SortExpression="F3" />
                <asp:BoundField DataField="F4" HeaderText="F4" SortExpression="F4" />
                <asp:BoundField DataField="G1" HeaderText="G1" SortExpression="G1" />
                <asp:BoundField DataField="G2" HeaderText="G2" SortExpression="G2" />
                <asp:BoundField DataField="G3" HeaderText="G3" SortExpression="G3" />
                <asp:BoundField DataField="G4" HeaderText="G4" SortExpression="G4" />
                <asp:BoundField DataField="H1" HeaderText="H1" SortExpression="H1" />
                <asp:BoundField DataField="H2" HeaderText="H2" SortExpression="H2" />
                <asp:BoundField DataField="H4" HeaderText="H4" SortExpression="H4" />
                <asp:BoundField DataField="I1" HeaderText="I1" SortExpression="I1" />
                <asp:BoundField DataField="I2" HeaderText="I2" SortExpression="I2" />
                <asp:BoundField DataField="I3" HeaderText="I3" SortExpression="I3" />
                <asp:BoundField DataField="I4" HeaderText="I4" SortExpression="I4" />
            </Columns>
        </asp:GridView>

how can i put break after 4 coloumn... <br/> doesnt work here

DataGrid shows no data fom URLmultiple request strings (data is there)

$
0
0

This is the URL. Appreciate any suggestions.

http://www.xxx.com.au/wizardreport.aspx?search=true&State=All&Location=All&Hazard=All&Priority=All&Status=All&Risk=All

 

 

Here is the Code

  

ICollection CreateDataSource()

    {

       

       

SqlConnection myConnection =newSqlConnection(ConfigurationSettings.AppSettings["DSN"]);

       

SqlDataAdapter myAdapter =newSqlDataAdapter();

       

SqlParameter prm;

       

SqlCommand myCmd =newSqlCommand();

       

string SQL ="SELECT * FROM [Inspection] INNER JOIN location ON Inspection.LocationID = location.LocationID WHERE ([location].[LocationID] = ISNULL(@Location,[location].[LocationID]) AND  [Location].[LASurvey1] = ISNULL(@State,[Location].[LASurvey1])AND [inspection].[RSurvey5] = ISNULL(@Hazard,[inspection].[RSurvey5]) AND [inspection].[RSurvey15] = ISNULL(@Priority,[inspection].[RSurvey15]) AND [inspection].[RSurvey8] = ISNULL(@Status,[inspection].[RSurvey8])AND [inspection].[RSurvey13] = ISNULL(@Risk,[inspection].[RSurvey13]))  ";

     

       

// Location

            prm =

newSqlParameter("@Location",SqlDbType.VarChar, 100);

            prm.Direction =

ParameterDirection.Input;

           

if (Request.QueryString["Location"] == "All")

            {

                prm.Value =

DBNull.Value;

            }

           

else

            {

                prm.Value = Request.QueryString[

"Location"];

            }       

            myCmd.Parameters.Add(prm);

        

// Priority  

        prm =

newSqlParameter("@Priority",SqlDbType.VarChar, 100);

        

        prm.Direction =

ParameterDirection.Input;

           

if (Request.QueryString["Priority"] == "All")

            {

                prm.Value =

DBNull.Value;

            }

           

else

            {

                prm.Value = Request.QueryString[

"Priority"];

            }

            myCmd.Parameters.Add(prm);

           

// State 

            prm =

newSqlParameter("@State",SqlDbType.VarChar, 100);

            prm.Direction =

ParameterDirection.Input;

           

if (Request.QueryString["State"] == "All")

            {

                prm.Value =

DBNull.Value;

            }

           

else

            {

                prm.Value = Request.QueryString[

"State"];

            }

            myCmd.Parameters.Add(prm);

       

//Hazard  

       

        prm =

newSqlParameter("@Hazard",SqlDbType.VarChar, 100);

            prm.Direction =

ParameterDirection.Input;

           

if (Request.QueryString["Hazard"] == "All")

            {

                prm.Value =

DBNull.Value;

            

            }

           

else

            {

                prm.Value = Request.QueryString[

"Hazard"];

            }

            myCmd.Parameters.Add(prm);

           

//Status 

       

        prm =

newSqlParameter("@Status",SqlDbType.VarChar, 100);

            prm.Direction =

ParameterDirection.Input;

           

if (Request.QueryString["Status"] == "All")

            {

                prm.Value =

DBNull.Value;

            }

           

else

            {

                prm.Value = Request.QueryString[

"Status"];

            }

            myCmd.Parameters.Add(prm);

           

//Risk  

       

            prm =

newSqlParameter("@Risk",SqlDbType.VarChar, 100);

            prm.Direction =

ParameterDirection.Input;

           

if (Request.QueryString["Risk"] == "All")

            {

                prm.Value =

DBNull.Value;

            }

           

else

            {

                prm.Value = Request.QueryString[

"Risk"];

            }

            myCmd.Parameters.Add(prm);

       myCmd.CommandText = SQL;

        myCmd.Connection = myConnection;

        myAdapter.SelectCommand = myCmd;

       

DataTable dt =newDataTable();

        myAdapter.Fill(dt);

        Session[

"Source"] = dt;

       

DataView dv =newDataView(dt);       

       

       

return dv;

    }

Need advise. Problem with connection pool. Function returning SqlDataReader.

$
0
0

Halo all

 

I have a problem with "timeout expired. Thei timeout periode elapsed prior to obtaining a connection from the pool. This may have occured because all pooled  connections were use  and max pool size was reached"

Then i explore and found out that i did not close my SqlDataReader, SqlDataAdapter, SqlCommand or my connection.

 

But i have a function that return a  SqlDataReader.

Is this function will cause a connection problem?

 

Thanks in advance

 

 

        Public Function GetDataReader(ByVal strSQL As String, ByVal DBCon As DB.DBConnection) As SqlDataReader
            Dim MyCommand As SqlCommand = New SqlCommand(strSQL, DBCon.GetConnection())

            If DBCon.GetConnection().State = ConnectionState.Closed Then
                DBCon.GetConnection().Open()
            End If

            Dim dr As SqlDataReader = MyCommand.ExecuteReader()

            Return dr

            dr.Close()

        End Function


Access datasource

$
0
0

Can some one please help me connecting to an access datasource or is this feature available, I am using visual studio 2012 express for web. I am creating a website from asp.empty website, I have trouble starting the website because their is no feature for access datasource in the data tab... If any one can help me with this, please do it would be appreciated!

No feature for selecting access datasource for configuring to database within datatab in toolbox  ...(No feature found in Visual Studio 2012 Express for web).

Need DataTable-like object for use with Stored Procedures

$
0
0

I have a website using web forms. The data layer consists of class files with functions which execute stored procedures and return DataTables used by my pages as the datasource for controls such as ListViews and GridViews. I'm happy with this structure for result sets; however, I am unhappy with this structure in dealing with the stored procedure output parameters and return values because those values are not inherently accessible in the DataTable. My solution has been to add columns to the DataTable containing the output parameter values (and, the return values).

For a multi-row result set, I am obviously producing redundant data for the output and return values which are duplicated in each row.

I tried to find an object similar to a DataTable, but with properties for output parameter and return value which are easily accessible. Am I missing something? If not, can you suggest a solution?

Here is an example: I have a stored procedure which asks survey questions related to a product being purchased. My stored procedure has 3 input parameters (@user_id, @session_id, @product_id), and returns a list of survey questions. Additionally, it returns output parameters including the user's first_name, last_name, the product name, purchase notes, status_code, status_message.

// Add parameters.
cmd.Parameters.AddWithValue("@user_id", Convert.ToInt32(HttpContext.Current.Session["user_id"]));
cmd.Parameters.AddWithValue("@session_id", HttpContext.Current.Session.SessionID);
cmd.Parameters.AddWithValue("@product_id", product_id);
cmd.Parameters.Add("@first_name", SqlDbType.VarChar, 30);
cmd.Parameters["@first_name"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@last_name", SqlDbType.VarChar, 30);
cmd.Parameters["@last_name"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@product_name", SqlDbType.VarChar, 512);
cmd.Parameters["@product_name"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@purchase_notes", SqlDbType.NVarChar, -1);
cmd.Parameters["@purchase_notes"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@status_code", SqlDbType.Int);
cmd.Parameters["@status_code"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@status_msg", SqlDbType.NVarChar, -1);
cmd.Parameters["@status_msg"].Direction = ParameterDirection.Output;

Multiple colum count

$
0
0

Hi

I have table with 4 players column like player 1, player 2 , player 3 and player 4. I am counting them like this

SELECT COUNT(*)FROM dbo.Hockey;

But it is showing 3, In my table i can mis player2 or some time  player 4. how i can count the number of players which will count player1 , 2 , 3, 4.

when i count it shows 3, but how i can count the other it should show 6

Player1

Player2

Player3

Player4

ABc

Alex

 

 

Alix

 

Robert

 

Zak

 

Jack

 

Thanks

Default sort order in ObjectDataSource

$
0
0
I have a GridView bound to an ObjectDataSource using my custom methods for retrieving data, paging, sorting, etc, but I would like to specify the default sort order for the first time the page is viewed.

I tried this by setting the SortExpression in the ODS_Selecting event like this:

if (!IsPostBack)
{
    e.Arguments.SortExpression = "SortColumn";
}

But that throws a seemingly unrelated error: 
"The data source 'ObjectDataSource1' does not support sorting with IEnumerable data."

(I am returning an array of a custom class to my grid, but everything works great if I don't have the Selecting event with these 3 lines of code.)

The reason I want to specify the sort order is so I can put a sort indicator on the column that is initially sorted by.  As I have it now, there is no sort indicator (because the SortExpression is "") and, even though I could set the default sort order in my select method, the user would have to click the column twice to get the descending sort.
First visit - SortExpression = ""
Click the column - SortExpression = "ColumnName"
Click the column again - SortExpression = "ColumnName DESC"

I would like to set the SortExpression on the first visit to the page.

Another related question - Why does the Selecting event fire twice?

SqlDataAdapter fails to return any data, but Reader.read() returns data?

$
0
0

Using SQL Server Management studio 2012 with VS 2012

Function is as follows:

public DataTable GetInvoice(){
string connstr=@"Data Source=........" //this connection string there is nothing wrong
string sql="SELECT * FROM Invoice";
Datatable dt= new DataTable();
using(SqlConnection con=new SqlConnection(connstr)){
try{
con.Open();
}
catch{

return dt;
}
using(SqlCommand cmd =new SqlCommand(sql,con)){
using(SqlDataAdapter adp=new SqlDataAdapter(cmd)){

adp.Fill(dt);
}
}



return dt;

}





}

This does not work, however if I use

SqlDataReader reader=cmd.ExecuteReader();

reader.Read();

int invoiceid=(int)reader["InvoiceID"];

It is able to read 

What does this mean?

Data Overflow The Parameter Data is too large to fit into the host field

$
0
0

I'm doing parameter substitution into an sql statement which is being used to change the SelectCommand in a SqlDataSource being used to load a  GridView.   The connection is an OleDb connection. 

The exception reads... {"Conversion failed for command parameter[0] '' because the data value overflowed the type used by the provider.
"}

...and the Inner exception reads... CWBZZ5012 Data overflow - the parameter data is too large to fit into the host field

...the SQL statement is...

SqlDataSource1.SelectCommand ="select order, recalled, edte, acct, sub, name, add1, add2, add3, code from lib.tablename t1 where code in ? and edte>= ? and edte <= ? order by t1.order desc"

...and the parameter substitutions are...

SqlDataSource1.SelectParameters.Add("@codelist", CodeList)

SqlDataSource1.SelectParameters.Add("@startingdate", startingdate)

SqlDataSource1.SelectParameters.Add("@endingdate", endingdate)

...with the fields defined in code as...

Dim CodeList AsString

Dim startingdate AsString
Dim endingdate AsString

...and viewing the contents of the fields in debug reveals...

CodeList value is ('CCM', 'CCS', 'CDR', 'CIR', 'CLM', 'CLP', 'CMC', 'CML', 'CMS', 'CNI', 'CRB', 'CRD', 'CRW', 'CTP', 'CTU')

startingdate value is 6/3/2013

endingdate value is 6/7/2013

Looks like it is failing on CodeList substition...can someone tell me why and what I need to do to make it work?

Thanks much in advance for any help, Roscoe

Convert DataGrid to Excel but include image when datagrid only has image URL

$
0
0

I have some code that converts a Datagrid to Excel and it works fine

But I now a DataGrid that includes a image . The image is genera; in the DatGrid  by using URL to a file on the server.

When converted to Ecel the image doesnt show because the URL wont work as the  EXcel sheet is displaying on my compter

I neeed to convert Link into .jpg file before converting to Excel

 

The code i am using  is below

   

privatevoid Excel(object sender, System.EventArgs e)

   {

     

//export to excel

        Response.Clear();

Response.Buffer =

true;

      Response.ContentType =

"application/vnd.ms-excel";

       Response.Charset =

"";

     

this.EnableViewState =false;

       System.IO.

StringWriter oStringWriter =new System.IO.StringWriter();

        System.Web.UI.

HtmlTextWriter oHtmlTextWriter =new System.Web.UI.HtmlTextWriter(oStringWriter);

       

//this.ClearControls(GridView1);

       MyDataGrid.RenderControl(oHtmlTextWriter);

        Response.Write(oStringWriter.ToString());

        Response.End();

    }

 


Error when Debug

$
0
0

Hi. Everybody can help me fix error

Code page asp have only a buton

When Debug it display

Server Error in '/' Application.


Specified argument was out of the range of valid values.
Parameter name: site

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.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: site

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace: 

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: site]
   System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +298

[HttpException (0x80004005): Specified argument was out of the range of valid values.
Parameter name: site]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874568
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18044

Sql IN clause fails on OleDb connection parameter substitution

$
0
0

I am using parameter substitution to build a query to be used as a SqlDataSource for a GridView...

SqlDataSource1.SelectCommand = "select order, recalled, edte, acct, sub, name, add1, add2, add3, code from libname.tablename t1 where t1.code in (?) and t1.edte >= ? and t1.edte <= ? order by t1.order desc"

...and I substitute the parameters...

SqlDataSource1.SelectParameters.Remove(SqlDataSource1.SelectParameters("@codelist"))
SqlDataSource1.SelectParameters.Remove(SqlDataSource1.SelectParameters("@startingdate"))
SqlDataSource1.SelectParameters.Remove(SqlDataSource1.SelectParameters("@endingdate"))
SqlDataSource1.SelectParameters.Add("@codelist", CodeList)
SqlDataSource1.SelectParameters.Add("@startingdate", startingdate)
SqlDataSource1.SelectParameters.Add("@endingdate", endingdate)

...and CodeList, startingdate and endingdate are all defined as string.  The strings will have values such as...

startingdate="06/03/2013"

endingdate="06/20/2013"

CodeList="CCM, CCS, CDR, CIR"

...and the query execution fails with...

CWBZZ5012 Data overflow - the parameter data is too large to fit into the host field. This is a programming error. 

...but if I change the value of CodeList to have one value...

CodeList="CCM"

...the query executes without any problem and returns the expected results.

The database is DB2 hosted on an iSeries server and the field "code" in the table is defined as char(3) .

Looks like query does not like the list of values but is fine with it as long as it has only one value that is the same length as the table field value.

Can someone kindly tell me what I need to do to make the IN work with the list of values?  Any help greatly appreciated, Roscoe

I've included the stack trace below...

 

CWBZZ5012 Data overflow - the parameter data is too large to fit into the host field. This is a programming error.

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.Data.OleDb.OleDbException: CWBZZ5012 Data overflow - the parameter data is too large to fit into the host field. This is a programming error.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[OleDbException (0x80040e21): CWBZZ5012 Data overflow - the parameter data is too large to fit into the host field. This is a programming error.]

[InvalidOperationException: Conversion failed for command parameter[0] '' because the data value overflowed the type used by the provider.
]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1081356
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForMultpleResults(tagDBPARAMS dbParams, Object& executeResult) +135
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +163
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +167
   System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +116
   System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +4
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +144
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +3404
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +96
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +225
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +127
   System.Web.UI.WebControls.GridView.DataBind() +29
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +108
   System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +43
   System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e) +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +209
   System.Web.UI.Control.PreRenderRecursiveInternal() +307
   System.Web.UI.Control.PreRenderRecursiveInternal() +307
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4834

how to format a SQL query string using asp:loginname in the WHERE clause

$
0
0

 ASP.NET 2.0/ SQL Server 2005/ Login Controls

I am a beginner of ASP.NET and has a problem when I do the query.

Problem:  It did not show any record after the user login.  After user login, it will query the table call match with condition Player_A = user_name ( login username) or Player_B =user_name (login username)

Does anyone know how to format a SQLquery string using asp:loginname
in the WHERE clause?

When I clicked the query button on the DESIGN view on microsoft visual studio, it worked fine and display 3 records.

But it did not display any record when I actually run the program.

Do I need to store the login name upon login w/in a
Session variable?

Can someone give me an example?

Thanks,

 

Frank

 

######################################################

 <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Member_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MessageContentPlaceHolder" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" Runat="Server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:BoundField DataField="Match_Id" HeaderText="Match_Id" SortExpression="Match_Id" />
            <asp:BoundField DataField="Player_A" HeaderText="Player_A" SortExpression="Player_A" />
            <asp:BoundField DataField="Player_B" HeaderText="Player_B" SortExpression="Player_B" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>"
        SelectCommand="SELECT * FROM Match WHERE (Player_A = @Player_A) OR (Player_B = @Player_B)">
        <SelectParameters>
            <asp:SessionParameter Name="Player_A" SessionField="LOGON_USER" Type="String" />

            <asp:SessionParameter Name="Player_B" SessionField="LOGON_USER" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>

DataAdapter Update not working.

$
0
0

Hi,

I am trying to update sql server 2008 table with dataset but this code is not working. I believe somethings wrong with my code, unable to find it, cmdUpdate got values but database is not getting updated. I am using DataAdapter for the first time so just new to all this. Could some please correct this. Any help would be highly appreciated.

ConfigurationManager.ConnectionStrings["My_onnectionstring"].ToString();
SQLcon.Open();
SqlDataAdapter SQLda = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();

SqlCommand cmd = new SqlCommand("Select * From My_Table", SQLcon);
SqlCommand cmdUpdate = new SqlCommand("Update My_Table Set Platform =@Platform Where AutoIndex =@AutoIndex", SQLcon);

SQLda.SelectCommand = cmd;
cmdUpdate.Parameters.Add("@Platform", SqlDbType.NVarChar).Value = tname;

SqlParameter parm = cmdUpdate.Parameters.Add("@AutoIndex", SqlDbType.Int);
parm.SourceVersion = DataRowVersion.Original;

SQLda.Fill(ds);
dt = ds.Tables[0];
SQLda.UpdateCommand = cmdUpdate;
SQLda.Update(dt);

SQLcon.Close();

Thanks.


Is this in the wrong forum? Frown

Connecting to asp.net to asp.net data base.

$
0
0

Hi,

I have 2 website in asp.net (VB) hosted in winows server. My 1st website has a access 2007 database in App_Data folder which is working fine and connectionstring is saved in web.config file with password.

Now i have another website asp.net(VB) hosted in another windows server. I want to access data from my 1st website. I am using dataset.xsd file in App_Code folder and some sqldatasource controls in pages.

Please help

Viewing all 956 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>