Setting Command Parameters For SQLDataSource

Dec 26, 2007

I have an SQLDataSource. The SQL is

 SELECT UserName, Category, ItemDescription, Size, Price, Reduce, Donate, Sold, ItemNumber, SoldDate, SoldPrice, Printed
FROM Tags
WHERE (Printed = @Printed1 OR Printed = @Printed2 OR Printed = @Printed3) ORDER BY ItemNumber DESC

The bit field "printed" can be NULL, True or False.

In the Selecting event of the SQLDataSource I have the following to show ALL records. But it does not work. If I remove these parameters it show ALL records.

e.Command.Parameters("@Printed1").Value = Nothing           'ASP.NET 2.0 using Visual basic
e.Command.Parameters("@Printed2").Value = True
e.Command.Parameters("@Printed3").Value = False


What am I doing wrong???

Thanks

Craig

View 10 Replies


ADVERTISEMENT

Setting SqlDataSource Update Command And Parameters Dynamically C#

Aug 31, 2007

Hello all,
Ok, I finally got my SqlDataSource working with Oracle once I found out what Oracle was looking for. My next hurdle is to try and set the Update Command and Parameters dynamically from a variable or radiobutton list. What I'm trying to accomplish is creating a hardware database for our computers by querying WMI and sending the info to textboxes for insertion and updating. I got that part all working nicely. Now I want to send the Computer name info to a different table column depending on if it is a laptop or desktop. I have been tossing around 2 ideas. A radiobutton list to select what it is and change the SQL parameters or do it by computer name since we have a unique identifier as the first letter ("W" for workstation, "L" for Laptop). I'm not sure what would be easiest but I'm still stuck on how this can be done. I posted this same question in here a few days ago, but I didn't have my SqlDataSources setup like I do now, I was using Dreamweaver 8, it is now ported to VS 2005. Below is my code, in bold is what I think needs to be changed dynamically, basically i need to change DESKTOP to LAPTOP...Thanks for all the help I've gotten from this forum already, I'm very new to ASP.NET and I couldn't do this without all the help. Thanks again!
 
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:CAT %>"ProviderName="<%$ ConnectionStrings:CAT.ProviderName %>" SelectCommand='SELECT * FROM "COMPUTER"' UpdateCommand="UPDATE COMPUTER SET DESKTOP = :DESKTOP, TECH = :TECH, SERVICE_TAG = :SERVICE_TAG WHERE USERNAME=:USERNAME">
<UpdateParameters>
<asp:ControlParameter Name="USERNAME" ControlId="txtUserName" PropertyName="Text"/>
<asp:ControlParameter Name="SERVICE_TAG" ControlId="txtServiceTag" PropertyName="Text"/>
<asp:ControlParameter Name="TECH" ControlId="txtTech" PropertyName="Text"/>
<asp:ControlParameter Name="DESKTOP" ControlId="txtComputerName" PropertyName="Text"/>
</UpdateParameters>
</asp:SqlDataSource>

View 1 Replies View Related

SqlDataSource Setting Of Parameters?

Aug 29, 2007

Hi,How do I set the parameters of an SqlDataSource programatically?I have tried the following...dsDraftBudgetPI.SelectParameters.Add(new Parameter("@person_id", TypeCode.Int32, pID.ToString()));But that didn't work.  I already have the parameter defined at design time so I don't need to create one I just want to set its value and then bind it to a ListBox to display the result.Thanks,Scott 

View 3 Replies View Related

Setting SqlDatasource Parameters From TextBox

Feb 17, 2008

I have a sqlDatasource with 3 parameters based on the input of 3 text boxes on the page. The datasource returns sales details for a company based on a from and to date. I am attempting to set the value of the 3 parameters in the Selecting event of the datasource control but I'm not getting any data back. If I set the values literally then I get data back. Also when I step through the code I can see the 3 parameters getting their values from the textboxes and the drop down list as they should. This is driving me insane as I'm new to .net and just can't see what is stopping me retrieving the data when using the form fields to set the datasources parameters. Below is the aspx and the code behind for the page. Thanks in advance for any help. aspx..... <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="LabelSales.aspx.cs" Inherits="LabelSales" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">        <asp:SqlDataSource ID="SqlDataSourceSales" runat="server" EnableCaching="false"        ConnectionString="<%$ ConnectionStrings:streetwisedigitalConnectionString %>"        SelectCommand="DL_GET_SALES_BY_LABEL" SelectCommandType="StoredProcedure" OnSelecting="SqlDataSourceSales_Selecting" >        <SelectParameters>            <asp:Parameter Name="fromDate" />            <asp:Parameter Name="toDate" />            <asp:Parameter Name="label" />        </SelectParameters>    </asp:SqlDataSource>        <asp:SqlDataSource ID="SqlDataSourceLabels" runat="server"         SelectCommand="select label_id, label_name from dl_label order by label_name asc"        ConnectionString="<%$ConnectionStrings:streetwisedigitalConnectionString%>">    </asp:SqlDataSource>    <div>        <table>            <tr>                <td>Start Date:&nbsp;</td>                <td>                    <asp:TextBox ID="FromDate" Runat="server" Width="70"/>                    <asp:Button ID="btnFrom" Runat="server" Text="..." UseSubmitBehavior="false" />                </td>            </tr>            <tr>                <td>End Date:&nbsp;</td>                <td>                    <asp:TextBox id="ToDate" Runat="server" Width="70" />                    <asp:Button ID="btnTo" Runat="server" Text="..." UseSubmitBehavior="false" />                </td>            </tr>            <tr>                <td>Label:&nbsp;</td>                <td>                    <asp:DropDownList ID="LabelList" Runat="server"                     DataSourceID="SqlDataSourceLabels"                     DataTextField="label_name" DataValueField="label_name">                    </asp:DropDownList>                </td>            </tr>            <tr>                <td colspan="2" align="right">                    <asp:Button ID="Button1" OnClick="SubmitButton_OnClick" Text="View Sales" runat="server" />                </td>            </tr>        </table>        <p>            <asp:GridView ID="GridViewSales" runat="server"                 DataSourceID="SqlDataSourceSales"                 ShowFooter="True"                 AllowSorting="True"                 AutoGenerateColumns="False"                 OnRowDataBound="GridViewSales_RowDataBound" EmptyDataText="No data to display.">                <Columns>                    <asp:BoundField DataField="cat_no" HeaderText="Cat No" />                    <asp:BoundField DataField="artist" HeaderText="Artist" />                    <asp:BoundField DataField="title" HeaderText="Title" />                    <asp:BoundField DataField="remix" HeaderText="Remix" />                    <asp:BoundField DataField="qty" HeaderText="Sold" />                    <asp:boundfield datafield="commission"                        HtmlEncode="False"                         dataformatstring="{0:F2}"                          headertext="Commission">                        <ItemStyle HorizontalAlign="Right" />                    </asp:boundfield>                </Columns>            </asp:GridView>        </p>    </div></asp:Content>code behind...using System;using System.Data;using System.Configuration;using System.Collections;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;public partial class LabelSales : System.Web.UI.Page{    int totalSold;    decimal totalCommssion;    protected void GridViewSales_RowDataBound(object sender, GridViewRowEventArgs e)    {        // add column totals to gridview        if (e.Row.RowType == DataControlRowType.DataRow)        {            totalSold += (int)DataBinder.Eval(e.Row.DataItem, "qty");            totalCommssion += (decimal)DataBinder.Eval(e.Row.DataItem, "commission");        }        // display the totals        else if (e.Row.RowType == DataControlRowType.Footer)        {            e.Row.Cells[0].Text = "<b>Total</b>";            e.Row.Cells[4].Text = totalSold.ToString();            e.Row.Cells[5].Text = totalCommssion.ToString("f2");        }    }        protected void Page_Load(object sender, EventArgs e)    {                   }    protected void SqlDataSourceSales_Selecting(object sender, SqlDataSourceSelectingEventArgs e)    {        // *** This method does not work ***        e.Command.Parameters[0].Value = FromDate.Text;        e.Command.Parameters[1].Value = ToDate.Text;        e.Command.Parameters[2].Value = LabelList.Text;        // *** This method works! ***        e.Command.Parameters[0].Value = "02/01/2007";        e.Command.Parameters[1].Value = "02/01/2008";        e.Command.Parameters[2].Value = "Fat!";    }    protected void SubmitButton_OnClick(object sender, EventArgs e)    {        SqlDataSourceSales.Select(DataSourceSelectArguments.Empty);    }}  Many thanks  Simon 

View 3 Replies View Related

Passing '% Variable %' To SqlDataSource Through E.Command.Parameters

Feb 23, 2008

 Hello all,I'm writing a site with one page that uses the session variable (User ID) to pick one user ID out of a comma separated list in the field Faculty. The default parameterized query designed in the SqlDataSource wizard only returns lines that contain an exact match:SELECT * FROM tStudents WHERE ([faculty] = @faculty) The query: SELECT * FROM tStudents WHERE ([faculty] LIKE '%userID%') works as I need when I hard code the query with a specific user ID into the SqlDataSource in the aspx page.  It will not work if I leave the @faculty parameter in it:SELECT * FROM tStudents WHERE ([faculty] LIKE '%@faculty%') e.Command.Parameters works to replace the @Faculty with a user ID, but again, adding the single quote and percentage sign either causes errors or returns no results.  I've tried several variations of:         string strEraiderID = "'%" + Session["eRaiderID"].ToString() + "%'";        e.Command.Parameters["@faculty"].Value = strEraiderID;no results are returned, not even the lines returned with the default select query.How do generate the equivalent of SELECT * FROM tStudents WHERE ([faculty] LIKE '%userID%') into the SqlDataSource? Thanks much! 

View 3 Replies View Related

Setting The SelectParameters Of SqlDataSource

Dec 30, 2005

Hi All,
I'm trying to set the SelectParameters of SqlDataSource from the code behind.
This is my query: SELECT * FROM [UploadSessions] WHERE ([OwnerID] = @OwnerID)And I need to set the value of the @OwnerID at the code behind since it is stored in an object.
How can I do it??
Thanks in advance
Bar
 

View 7 Replies View Related

SQL Setting Command

Jul 20, 2005

HiIs there a sp command I can issue which will show me what the "sortorder" etc for my MSsql server.I need to re-install it, but need to record what custom setting it hasif any before I wipe it.I have to reinstall to reconfigure the RAID arry under itThanks

View 1 Replies View Related

Setting The Value Of A SqlDataSource.SelectParameter Object

Sep 13, 2006

I am trying to set the value of a SqlDataSource parameter named "InvestmentGroup" with the following code:ProjectData.SelectParameters["InvestmentGroup"] = Request.QueryString[0];ProjectData.DataBind();When I try this, I get an error saying that the right side is a string and the left side is not....but I cannot find a property of the SelectParameters["InvestmentGroup"] object like Value or something that would allow me to set the value of the parameter with a string. Please help!

View 4 Replies View Related

Programmatically Setting UpdateParameters For A SQLDataSource Control

Sep 8, 2006

I need to provide defaults and sometimes overrides for items in SQLDataSource's UpdateParameters. I am attempting to do this in a FormView's ItemUpdating and ItemInserting events as follows: //========================================================================
// FormView1_ItemUpdating:
//========================================================================
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) {
// not sure if this is the bets place to put this or not?
dsDataSource.UpdateParameters["UpdatedTS"].DefaultValue = DateTime.Now.ToString();
dsDataSource.UpdateParameters["UpdatedUserID"].DefaultValue = ((csi.UserInfo)Session["UserInfo"]).QuotaUserID;
}
 In the example above I am attempting to set new values for the parameters which will replace the existing values. I have found that using the DefaultValue property works ONLY if there is no current value for the parameter.  Otherwise the values I specify are ingnored.The parameters of an ObjectDataSource provide a Value property but SQLDataSource parameters do not.How can I provide an override value without needing to place the value in the visible bound form element???If you can answer this you will be the FIRST person ever to answer one of my questions here!!!Thanks,Tony 

View 2 Replies View Related

Need Help Setting Default DateTime On SqlDataSource Control

Jan 21, 2007

I thought this would be easy.  I have a repeater control and a sqldatasource control.  I am trying to filter the select statement using DateTime.Now.ToString() and keep getting an invalid date string format.  The control is on a content page in my asp.net site.  On the master page this <%= DateTime.Now.ToLongDateString() %>  works to display the current date.  If I try and put <%= DateTime.Now.ToString() %> in the Default value of the SelectParameter it does not work.  No intellisense either so I am assuming I am missing something.  Here is the code... pretty basic really.
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="sqlDSnews">
<ItemTemplate>
<h3><%# Eval("newTitle")%></h3>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource
ID="sqlDSnews"
runat="server"
ConnectionString="<%$ ConnectionStrings:XXXX%>"
SelectCommand="SELECT [newTitle], [newsDetails], [dateExpires], [newsImage], [dateCreated] FROM [News] WHERE (([GroupID] = @GroupID) AND ([dateExpires] >= @dateExpires))">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="GroupID" QueryStringField="Gid" Type="Int32" />
<asp:Parameter Name="dateExpires" DefaultValue='<%= DateTime.Now.ToString() %> 'Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
** NOTE the DateTime does not show up in blue - if that helps with a solution **

View 5 Replies View Related

SqlDataSource SelectCommand - Dynamically Setting The Name Of The Table?

May 7, 2007

Can you dynamically set the name of the table in the SelectCommand section of the SqlDataSource? (If it is relevant, I code in C#)
 For example,
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:Test-MySQL %>" ProviderName="<%$ ConnectionStrings:Test-MySQL.ProviderName %>" SelectCommand="SELECT * FROM TestTable">
I would like to replace 'TestTable' with the name of a table that is extracted from a string array in the code-behind.
Appreciatively,Peter

View 4 Replies View Related

Setting The Datasource Select Command

May 22, 2008

Can someone tell me why the syntax checker is choking on the following code? It doesn't like the SQLDataSource1 reference. Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
SqlDataSource1.SelectCommand = "SELECT * FROM users WHERE username='" + Trim(txtUsername.Text) + "' AND password='" + Trim(txtPassword.Text) + "'"
End Sub

 
Thanks

View 6 Replies View Related

ASP: SqlDataSource - Select Command

Aug 10, 2007

I am using  <asp:SqlDataSource ID and for the Select Command, the following, where the WHERE clause ... for an exact match (=) works correctly:
SelectCommand="SELECT [PatientID], [MedRecord] , [Accession], [FirstName], [LastName], [Address1] FROM [ClinicalPatient] WHERE (LastName = @LastName) ORDER BY [LastName]DESC">
 I would like to do a "LIKE" search where the LastName Parameter is matched using "LIKE".  In  this situation how would the syntax be written.... I tried:
LastName LIKE '%" & LastName & "%'"
But I get an error???? Any suggestions, please...
Thanks !!

View 4 Replies View Related

SqlDataSource Insert Command....

Oct 12, 2007

Hello all,
I am having problem to insert the record into database from sqldatasource control. my code is listed below, and i can't find anything why it cause the exception...
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet"                ConnectionString="<%$ ConnectionStrings:WebsiteDataConnection %>"                 SelectCommand="SELECT * FROM [ServiceAgents]"                InsertCommand="INSERT INTO ServiceAgents VALUES(@Ser_STATE, @Ser_CITY, @Ser_AGENT, @Ser_PHONE, @Ser_EQUIPMENT)">                                <InsertParameters>                    <asp:FormParameter Name="Ser_STATE" FormField="TextBox_state"/>                    <asp:FormParameter Name="Ser_CITY" FormField="TextBox_city"/>                    <asp:FormParameter Name="Ser_AGENT" FormField="TextBox_agent"/>                    <asp:FormParameter Name="Ser_PHONE" FormField="TextBox_phone"/>                    <asp:FormParameter Name="Ser_EQUIPMENT" FormField="TextBox_equip" />                   </InsertParameters>            </asp:SqlDataSource>
The table has got the fields that needed for insert command, for example:
            <table>                    <tr>                        <td>State:</td>                        <td>                            <asp:TextBox ID="TextBox_state" runat="server"></asp:TextBox>                            <asp:RequiredFieldValidator                            id="RequiredFieldValidator1"                            runat="server"                            ControlToValidate="TextBox_state"                            Display="Static"                            ErrorMessage="Please enter a state." />                        </td>                    </tr>                                        <tr>                        <td>City:</td>                        <td>                            <asp:TextBox ID="TextBox_city" runat="server"></asp:TextBox>                            <asp:RequiredFieldValidator                            id="RequiredFieldValidator2"                            runat="server"                            ControlToValidate="TextBox_city"                            Display="Static"                            ErrorMessage="Please enter a city." />                        </td>                    </tr>                                        <tr>                        <td>Agent:</td>                        <td>                            <asp:TextBox ID="TextBox_agent" runat="server"></asp:TextBox>                            <asp:RequiredFieldValidator                            id="RequiredFieldValidator3"                            runat="server"                            ControlToValidate="TextBox_agent"                            Display="Static"                            ErrorMessage="Please enter a agent." />                        </td>                    </tr>                                        <tr>                        <td>Phone:</td>                        <td>                            <asp:TextBox ID="TextBox_phone" runat="server"></asp:TextBox>                            <asp:RequiredFieldValidator                            id="RequiredFieldValidator4"                            runat="server"                            ControlToValidate="TextBox_phone"                            Display="Static"                            ErrorMessage="Please enter a phone No." />                        </td>                    </tr>                                        <tr>                        <td>Equipment:</td>                        <td>                            <asp:TextBox ID="TextBox_equip" runat="server"></asp:TextBox>                            <asp:RequiredFieldValidator                            id="RequiredFieldValidator5"                            runat="server"                            ControlToValidate="TextBox_equip"                            Display="Static"                            ErrorMessage="Please enter a equipment." />                        </td>                    </tr>                                        <tr>                        <td></td>                        <td>                            <asp:Button ID="Button2" runat="server" Text="Add" OnClick="addEntry"                             BackColor="#FFFBFF"                             BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px"                            Font-Names="Verdana" Font-Size="1.0em" ForeColor="#284775"/>                          </td>                    </tr>                </table>
And in the code i just called: SqlDataSource1.Insert(); Then the page gives me the exception like:
Cannot insert the value NULL into column 'STATE', table 'WebsiteData.dbo.ServiceAgents'; column does not allow nulls. INSERT fails. The statement has been terminated.
But i actually input all the required text in the textbox.... Any idea guys?
Thanks

View 2 Replies View Related

SqlDataSource Select Command

Nov 15, 2007

I have a SqlDataSource object that is bound to a GridView control. I have configured the SqlDataSource with a default select command. Under certain values of query strings on the URL for this page (Default.aspx), I want to change the select command. So I put the statements in the Page_Load method for Default.aspx to define SqlDataSource1.SelectCommand. The changed SelectCommand works fine for the first page of GridView data and shows 5 GridView pages, but if I switch to one of the other pages, it seems to revert to the default SelectCommand (which generates 19 GridView pages). I assume I should put my code to change the SelectCommand somewhere else. Can someone help me with where to put it? Thanks!

View 1 Replies View Related

SqlDataSource And Insert Command

Nov 20, 2007

I get the following error, when I try to create a company. Any help would be appreciated. Error Code: Cannot insert the value NULL into column 'CompanyName', table 'Telemetry.dbo.Company'; column does not allow nulls. INSERT fails.The statement has been terminated. Here is my aspx file: <table>     <tr ><td style="width:110px"><b>Company Name:</b></td><td ><asp:TextBox ID="CompanyName" Text="" runat="server" width="250px"/></td></tr>    <tr><td ><b>Phone Number:</b></td><td ><asp:TextBox runat="server" ID="CompanyPhone" Text=""  Width="250px"/></td></tr>                        <tr><td ><b>Company E-mail:</b></td><td ><asp:TextBox runat="server" ID="CompanyEmail" Text="" Width="250px"/></td></tr>                        <tr><td ><b>Street Address:</b></td><td><asp:TextBox runat="server" ID="AddressStreet" Text="" Width="250px"/></td></tr>            <tr><td ><b>City :</b></td><td><asp:TextBox runat="server" ID="AddressCity" Text="" Width="200px"/></td></tr>            <tr><td ><b>State/Province:</b></td><td><asp:TextBox runat="server" ID="AddressState" Text="" Width="150px"/></td></tr>            <tr><td ><b>Zip Code:</b></td><td><asp:TextBox runat="server" ID="AddressZip" Text="" Width="150px"/></td></tr>            <tr></tr>                </table>          <asp:Button ID="Submit" runat="server" OnClick="Submitinfo" />     <br />    <asp:SqlDataSource ID="sqlCreateCompany" runat="server" ConnectionString="<%$ ConnectionStrings:SqlServer1 %>"        InsertCommand="INSERT INTO Company(CompanyName, CompanyPhone, CompanyEmail, AddressStreet, AddressCity, AddressState, AddressZip) VALUES (@CompanyName, @CompanyPhone, @CompanyEmail, @AddressStreet, @AddressCity, @AddressState, @AddressZip)"        SelectCommand="SELECT [CompanyID], [CompanyName], [CompanyPhone], [CompanyEmail], [AddressStreet], [AddressZip], [AddressState], [AddressCity] FROM [Company]"  >                <InsertParameters>            <asp:FormParameter Name="CompanyName"  FormField="CompanyName"/>            <asp:FormParameter Name="CompanyPhone" FormField="companyPhone" />            <asp:FormParameter Name="CompanyEmail" FormField="CompanyEmail" />           <asp:FormParameter Name="AddressStreet" FormField="AddressStreet" />                       <asp:FormParameter Name="AddressCity" FormField="AddressCity" />            <asp:FormParameter Name="AddressState" FormField="AddressState" />            <asp:FormParameter Name="AddressZip" FormField="AddressZip" />                    </InsertParameters>            </asp:SqlDataSource> .....Behind the code.............. protected void Submitinfo(object sender, EventArgs e)    {        //TextBox t = (TextBox)FormView1.FindControl("CompanyName");        sqlCreateCompany.Insert();    }  .........Database Company Table Design..............CompanyID    int    UncheckedCompanyName    varchar(100)    UncheckedCompanyPhone    varchar(50)    CheckedCompanyEmail    varchar(100)    CheckedAddressStreet    varchar(100)    CheckedAddressCity    varchar(50)    CheckedAddressState    varchar(2)    CheckedAddressZip    varchar(5)    CheckedCompanyLogo    varchar(100)    Checked  

View 2 Replies View Related

Simple ALTER Command Setting DEFAULT Help

Apr 21, 2008

Hi all, I am trying to do a very basic ALTER Command and am trying to change its DEFAULT value. Code below is what I currently have:





Code Snippet

ALTER TABLE Table_1

ALTER COLUMN TEST VARCHAR(1000) NULL DEFAULT 2

Thanks, Onam.

*UPDATE* I found this code but are there alternative methods? Additionally, if I was to update its DEFAULT value again how would I go about doing that? Do I first have to remove the CONSTRAINT and then run the command?





Code Snippet

ALTER TABLE Table_1 ADD CONSTRAINT DF_Albumns_Comment DEFAULT 2 FOR TEST

View 8 Replies View Related

Sqldatasource Setting Reset After Page Postback, Could Anyone Give Me A Hand On This

Nov 25, 2005

Hi, I have created a search page which needs to perform different
search function in same page. I have setuped a sqldatasource then
manual
setup the connection string and command inside the codefile. So the
select command can be various depends on the event. The problem is
all of those setting will be reset after I click on the pageindex in
the girdview control to go to next pages. Since this gridview is linked

with this sqldatasource control, I need to restore the connection
string/command when user choose decide to view next page of data inisde
the
gridview.

I think I must have done something wrong in here becuase it will end up
retrieving  the total amount of data when everytime user choose to
view next
or perivous page.

Can someone give me a hand on this ? Thanks

View 1 Replies View Related

Using Sqldatasource Insert Command Manually

Aug 4, 2006

hi i have an sqldatasource which has an insert command - a stored procedue is used.I have a text box with a button next to it . it is not in a datagrid.on the onclick event I would like to pass the value of the text box to the sqldatasource insert parameter ( it only expects this one parameter , and use the sqldatasource to do the insert basically doing a manual insert using the sqldatasource.does anyone know if this is possible thanks

View 2 Replies View Related

Runtime Sqldatasource Delete Command

Aug 12, 2006

i need to dyanamically generate my SQL commands so to do that i am generating sqldatasource commands programmatically rather declaratively. SELECT commands seems to work fine but DELETE isnt doing anything, here is my code:
 
SqlDataSource sdsConsultant = new SqlDataSource();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
loadDataSet();  //it just loads dataset used by formview
initializeSDS();
}


}
protected void initializeSDS()
{
string strConnection = ConfigurationManager.ConnectionStrings["myDB"].ToString();
sdsConsultant.ConnectionString = strConnection;

//SELECT
sdsConsultant.SelectCommand = "SELECT * FROM Consultants WHERE (id=@id)";
QueryStringParameter id = new QueryStringParameter("id", "id");
sdsConsultant.SelectParameters.Add(id);

//DELETE
sdsConsultant.DeleteCommand = "DELETE * FROM Consultants WHERE (id=@id2)";
QueryStringParameter id2 = new QueryStringParameter("id2", "id");
sdsConsultant.DeleteParameters.Add(id2);

//UPDATE
Page.Controls.Add(sdsConsultant);
FormView1.DataSource = sdsConsultant;
FormView1.DataBind();
}
 
my formview control looks like:
<asp:FormView DefaultMode="Edit" ID="FormView1" runat="server" DataKeyNames="id"
OnItemDeleted="FormView1_ItemDeleted"
OnItemDeleting="FormView1_ItemDeleting">
 
the DELETE doesnt execute and the OnItemDeleted event doesnt do anything either. am i doing something wrong here? plz help
 

View 2 Replies View Related

[ask] How To Invoke Sqldatasource Command In Method??

Apr 24, 2007

hello everybody, i have a question to ask, suppose i have a sqldatasource, can i use it in a method??this is my case, i need to make a new method to count the rows in a datagrid, so i will have to read the sqldatasource. the problem is, how to retrieve it?? usually i use the built in sqldatasource_selected to count the rows.... is there any other way?? 

View 6 Replies View Related

SqlDataSource.Select Command Not Working?

May 26, 2007

My compiler says that the line in bold below is illegal. The error msg I'm getting is: No overload for method 'select' takes '0' arguments. How can I correct this error and execute a SELECT?
 protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource2.Select ();
 }
 protected void SqlDataSource2_Selected(object sender, SqlDataSourceStatusEventArgs e)
{string strReadyFirstName = e.Command.Parameters["@FirstName"].Value.ToString();string strReadyLastName = e.Command.Parameters["@LastName"].Value.ToString();
}
 <asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [User_ID], [User_Name], [FirstName], [LastName], [Company_Name], [Department_Name] FROM [CompanyDepartment] WHERE ([User_Name] = @User_Name)" OnSelected="SqlDataSource2_Selected">
<selectparameters>
<asp:sessionparameter DefaultValue="TheirUserName" Name="User_Name" SessionField="TheirUserName" Type="String" />
</selectparameters>
</asp:SqlDataSource>

View 1 Replies View Related

Dynamic SELECT Command In SqlDataSource

Jul 20, 2007

I have a GridView (that uses SqlDataSource1) and a Dropdownlist.  Depending upon the value selected on the DropDownList I need to select different stored procedures for the gridview.  The problem is that I can do it without taking SqlDataSource1 by using DataSet or DataTable.  But, I need to Use SQLDataSource1 for easy way of Header SORTING.  So, is there any way to change the SQLDatasource1.SELECT Command dynamically. So that, I can use different queries for the Single DataGrid. I have attached the sample code of the SqlDataSource1 I'm using.  I need to change the Command i.e. SelectCommand="usp_reports_shortages" to "usp_reports_shortagesbyID" and "usp_reports_shortagesbyDate"     depending on the value selected in the dropdownlist.  So, is there any way to do this????<asp:SqlDataSource ID="SqlDataSource1"
runat="server"
ConnectionString="<%$
ConnectionStrings:TESTDrivercommunication %>"


    SelectCommand="usp_reports_shortages" SelectCommandType="StoredProcedure">


    <SelectParameters>


        <asp:ControlParameter ControlID="lblDriver" Name="date1" PropertyName="Text" Type="DateTime" />


        <asp:ControlParameter ControlID="lblTODate" Name="date2" PropertyName="Text" Type="DateTime" />


        <asp:ControlParameter ControlID="DDlDriver" Name="driver" PropertyName="SelectedValue"


            Type="Int32" />


        <asp:SessionParameter Name="week" SessionField="s_week" Type="DateTime" />


    </SelectParameters>


</asp:SqlDataSource>

View 1 Replies View Related

Using @@IDENTITY In The Sqldatasource Insert Command

Jan 11, 2008

I apologise if i have not posted this in the correct Topic before i start. But was uncertain where to post this query.
This is my first project in ASP.NET, MS Visual Web Developer 2005 Express and SQL Server 2005 Express. I have relatively little experience, so please bare with me.
I have managed to create a form that inserts data into a table and then inserts the Automatically Created Primary Key(as a foreign key) in another table. I have done this by inserting what is highlighted in red in the code of my InsertCommand below (Please scroll across to the end of the code):-InsertCommand="INSERT INTO [PrinterModel] ([Model], [PrinterMakeID], [CartridgeCode], [PartCode], [Duplex], [NIC], [Wireless], [Parallel], [USB], [Colour], [PrinterTypeID]) VALUES (@Model, @PrinterMakeID, @CartridgeCode, @PartCode, @Duplex, @NIC, @Wireless, @Parallel, @USB, @Colour, @PrinterTypeID) INSERT INTO [Model] ([PrinterModelID],[TypeID]) VALUES (@@IDENTITY, 3)" Can you see any problems that may arise from using this method. This project is an Asset Management System and will be used by no more than a handful of users. My Concern is the use of the @@IDENTITY (As it only stores the last Key used). Should I be using it here? If there is more than one user inserting into tables (Chances of this happening are very low), will the correct Primary key be insert to the table in the above code?Thank you for your comments.

View 2 Replies View Related

Dynamic SqlDataSource Select Command?

Apr 25, 2008

I am trying to implement an "advanced search" feature on my ASP.NET 2.0 web form.  I have a GridView control and a SqlDataSource.  The SqlDataSource control successfully retrieves data when the SelectCommand attribute is set in the aspx page.  I need to make it so when a user clicks on a button, it can take a value from a text box and use it in the WHERE clause.  I have tried setting the SelectCommand programmatically and then DataBinding but it never accepts the new SelectCommand. What can I do to fix this?

View 5 Replies View Related

How To Trigger The Update Command Of The SQLDataSource

Jun 13, 2006

Hi - I'm using .net2, and have a gridview, populated by a SQL Datasource (Edit, Insert, Delete, Select).
Like we all used to do with the datagrid, I've added text boxes into the footer, and a link button, which I'd like to use to fire the Update command.
How do I get the link button to trigger the update command?
Thanks, Mark

View 1 Replies View Related

Setting Parameters @ Runtime

Jan 24, 2006

Here is the code I am trying to use to set a update parameter at runtime.  (Depending on what linkbutton a user clicks on the STATUS_ID value will change.)
SqlDataSource1.UpdateParameters("STATUS_ID").DefaultValue = 33332Here are my parameters:
<UpdateParameters>
<asp:Parameter Name="CUSTOMER_ID" Type="Decimal" />
<asp:Parameter Name="RECEIVED_BY" Type="String" />
<asp:Parameter Name="CALL_DATETIME" Type="DateTime" />
<asp:Parameter Name="AREA_ID" Type="Decimal" />
<asp:Parameter Name="CLASS_ID" Type="Decimal" />
<asp:Parameter Name="STATUS_ID" Type="Decimal" /></UpdateParameters>Sqldatasource1 is the name of my datasource control.  Any thoughts?

View 2 Replies View Related

Setting Service Account To LocalSystem Via Command Prompt

Dec 5, 2007



Hello,

I was wondering if there was any way to set the service account on sql server 2005 express to Local System via command prompt.

To giva some background to this issue, I am installing 2005 express via command prompt, however, the default service account is network I believe. However, when running this, I keep getting an "error 3415" whenever I try to attach a database, which states that the files are "read only", which they are not. However, when setting the service account to local or set the security mode to windows authenticaiton, I can attach just fine.

The parameters I use to install are pretty standard:


"/qb ADDLOCAL=ALL INSTANCENAME=<name>SAPWD=<pwrd> SECURITYMODE=SQL DISABLENETWORKPROTOCOLS=0 SQLAUTOSTART=1"

So I was wondering if there was some way to set the service account to local system to local using some command prompt parameter. OR if there was another way around the error 3415 that will enable me to attach a database, that I do not know about that I can use, preferrably via command prompt, but anything will be fine at this point.

Thank you all in advance.

View 6 Replies View Related

SqlDataSource Parameters

Apr 4, 2007

Is
it possible to specify different parameters for the
select/update/delete stored procedures used by a sqldatasource? When I
'configure the datasource' it lists the different stored procedures for
each command, but when it comes to specifying the parameters it only
lets me do so for the select command. Is there another way to do this
for the other commands?

I have tried doing it manually in the aspx file (using the
DeleteParemeters etc), but I don't know how to reference a specific
cell in the selected row of the gridview for the controlparameter). Any
thoughts?

View 4 Replies View Related

Parameters Of SqlDataSource

Apr 17, 2007

Hello I need help withsetting parameters for SqlDataSource
I have a simple program. I want display date from  database on MS SQLSERVER from the table USERS only for  current sing on user select by his login.
 I save into this  variable login current user:   string @LOGIN = Context.User.Identity.Name;
I have already done with this way without SqlDataSource:
string login = Context.User.Identity.Name;
SqlConnection conn1 = new SqlConnection("server=CR\SQLEXPRESS;database=myData;integrated security=SSPI");
conn1.Open();
SqlCommand cmd1 = new SqlCommand(" SELECT  IN_OUT.TIME_START,  IN_OUT.TIME_END, FROM  IN_OUT INNER JOIN USER ON USER.USER_ID=IN_OUT.RC_USER_ID where USER.LOGIN=@LOGIN", conn1);
cmd1.Parameters.Add("@LOGIN", SqlDbType.NVarChar, 50);
cmd1.Parameters["@LOGIN"].Value = login;
1.Parameters.Add("@LOGIN", SqlDbType.NVarChar, 50);
cmd1.Parameters["@LOGIN"].Value = login;
Now I don't know how to do with SqlDataSource, what I have to set in SqlDataSource1 yet
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
ProviderName="<%$ ConnectionStrings:myConnectionString.ProviderName %>" SelectCommand="SELECT IN_OUT.TIME_START, IN_OUT.TIME_END, FROM IN_OUT INNER JOIN USER ON USER.USER_ID=IN_OUT.RC_USER_ID where USER.LOGIN=@LOGIN">
</asp:SqlDataSource>

View 1 Replies View Related

Parameters.Add With SqlDataSource

Dec 2, 2007

Does anybody knows how to use parameters.add with SqlDataSource?

View 4 Replies View Related

How To Value Parameters For Sqldatasource

Dec 9, 2007

I set up a sqldatasource based on a stored procedure which takes one parameter.  The sqldatasrouce wizard generates the following code for the parameter below.  The question is how do I value the DeptID parameter on the load of the form.  I tried the following code in the load of the page, but get a null reference error:Me.SqlDataSource1.InsertParameters("DeptID").DefaultValue = Session("DeptID")     <asp:SqlDataSource ID="SqlDataSource1" runat="server"             ConnectionString="<%$ ConnectionStrings:FDConn %>"             SelectCommand="GetTruckStatus" SelectCommandType="StoredProcedure">            <SelectParameters>                <asp:Parameter Name="DeptID" Type="Int32"  />            </SelectParameters>        </asp:SqlDataSource>        <radG:RadGrid ID="RadGrid1" runat="server">        </radG:RadGrid>

View 3 Replies View Related

SQLDataSource: How To Use Parameters

Dec 22, 2005

I need to do some select & update from VB code behind a web page. Using VS2005, ASP.NET.
To me, the most logical approach would be to use a SqlDataSource. I can select the connection string, predefine select, insert and update queries and call the select(), and other commands from this control.
I need to use parameters in the queries but I cannot connect parameters straight to controls, I need to do it from VB. But nowhere can I find how to set the parameter values from code. I can find all kind of examples from VS2003 or using SqlCommand, but it should be possible from this control as well, but the help documentation is very poor in this respect.
Please provide me with some example.
Kind regards
 

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved