Select in SqlDataSource

Last post 07-08-2009 7:54 AM by Jian Kang - MSFT. 4 replies.

Sort Posts:

  • Select in SqlDataSource

    07-04-2009, 12:23 PM
    • Member
      6 point Member
    • FrankEnem
    • Member since 06-24-2009, 11:58 AM
    • Posts 13

    Hi, I have created a datasource sqldatasource1. I have issued a select statement in a view to updating a record.

    --------------------Partial code 

     SqlDataSource1.SelectCommand = "SELECT * FROM ACCTMASTER WHERE ACCOUNTID =" + Me.AccountID.Text

    SqlDataSource1.SelectParameters.Clear()

    SqlDataSource1.SelectParameters.Add("PAYERID", Me.PayerID.Text)

    Dim dv As DataView = DirectCast(SqlDataSource1.[Select](DataSourceSelectArguments.Empty), DataView)

    Dim tab As DataTable = dv.Table

     (tab.Rows.Count > 0) Then

    ---- and so on

    -------------------end of partial code

    Pls I want to return the individual fields of the table AcctMaster with  the  SELECT statement.

    for instance,

    Dim  V_AccountId as String = AcctMaster.AccountId

     

  • Re: Select in SqlDataSource

    07-04-2009, 5:27 PM
    Answer

    Hmmm.  Not quite sure why you have not use a parameter for the AccountID value, but then added a parameter that you have not provided a value for or used in your SQL.  Also, I don't know why you are using a DataTable, when a DataReader will do.

    As far as referencing the values using their tablename.fieldname is concerned, that won't work. Read this: http://www.mikesdotnetting.com/Article.aspx?ArticleID=45


    Regards Mike
    [MVP - ASP/ASP.NET]
    My site    Please help - URGENT!!!    What ASP.NET can and can't do
  • Re: Select in SqlDataSource

    07-06-2009, 6:02 AM
    • Member
      6 point Member
    • FrankEnem
    • Member since 06-24-2009, 11:58 AM
    • Posts 13
    Hi, How then can I use a parameter to return the value of individuasl colums. You mention Dataset and Datareader well and fine, if I use a datareader, how will the code be? ---This is the smaple code for SqlDataSource1 DataView dvSql = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); foreach (DataRowView drvSql in dvSql) { Label3.Text = drvSql["FirstName"].ToString(); } OleDbDataReader rdrSql = (OleDbDataReader)SqlDataSource2.Select(DataSourceSelectArguments.Empty); while (rdrSql.Read()) { Label4.Text = rdrSql["LastName"].ToString(); } rdrSql.Close(); ------- When I put down the above code, line one gave me an error message. pls do explain this and how I can use the DataReader
  • Re: Select in SqlDataSource

    07-06-2009, 8:24 AM

    FrankEnem:
    When I put down the above code, line one gave me an error message.

    What is the error message?


    Regards Mike
    [MVP - ASP/ASP.NET]
    My site    Please help - URGENT!!!    What ASP.NET can and can't do
  • Re: Select in SqlDataSource

    07-08-2009, 7:54 AM
    Answer

    Hi Frank,

    FrankEnem:

    Pls I want to return the individual fields of the table AcctMaster with  the  SELECT statement.

    How then can I use a parameter to return the value of individuasl colums.

     

    Could you please clarify it or provide more detail? You may refer to the tutorial below:

    Using Parameterized Queries with the SqlDataSource
    http://www.asp.net/learn/data-access/tutorial-48-vb.aspx

    FrankEnem:

    OleDbDataReader rdrSql = (OleDbDataReader)SqlDataSource2.Select(DataSourceSelectArguments.Empty);

    When I put down the above code, line one gave me an error message. pls do explain this and how I can use the DataReader

    Please set the SqlDataSource.DataSourceMode property set to “DataReader”, and retrieve the data as follows:

    SqlDataReader dr = (SqlDataReader)SqlDataSource1.Select(DataSourceSelectArguments.Empty);


    Please refer to the following document for more detail:

    SqlDataSource.Select Method
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.select.aspx

    Jian Kang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (5 items)