SqlDataSource UpdateCommand Plus Insert

Oct 22, 2007

SqlDataSource UpdateCommand plus Insert

I have a SqlDataSource with an UpdateCommand but besides that i need also an Insert command triggered on the same update command.

That´s because i need to update a record and at the same time include a log of that update in another database.

Thanks

View 3 Replies


ADVERTISEMENT

UpdateCommand For SQLDataSource

Apr 13, 2007

I have a custom setup so bear with me here in my explanation.  The SelectCommand for my SQLDataSource gets data from a table using a QueryString for filtering by the record ID. A Repeater control is then used to populate the data into different Textboxes on the page (and a custom HTML-editor control). This works 100%.  I'm trying to use the UpdateCommand for the SQLDataSource to then update the record with the data that the user changes. (Example: FieldA is "foo" and the user changes it to "foobar". When the form is submitted, it then updates FieldB to be "foobar").  The form is being submitted, but the data isn't being updated at all.  Any ideas? Thanks for the help in advance. 

View 11 Replies View Related

Sqldatasource.updatecommand

May 11, 2006

I have a SQLDataSource that has an UpdateCommand assigned to it.  At certain times I may need to change the UpdateCommand to save different info to the database.  I thought I would be able to use sqldatasource.updatecommand.equals() to change the UpdateCommand and then call the sqldatasource.update method, but it didn't work...the default command was still used.  Is there something else I need to change?  I figured my next option would be to create another sqldatasource.  Any help would be great!

View 4 Replies View Related

UpdateCommand In Sqldatasource Control

Oct 15, 2007

Hello all,
I am trying to update the record which involed the modification of key in Datakeynames, but when i click the update button from gridview, it doesn't allow to change the value of modified column.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet"                 ConnectionString="<%$ ConnectionStrings:WebsiteDataConnection %>" OldValuesParameterFormatString="old_{0}"                SelectCommand="SELECT * FROM [ServiceAgents]"                InsertCommand="INSERT INTO ServiceAgents VALUES(@Ser_STATE, @Ser_CITY, @Ser_AGENT, @Ser_PHONE, @Ser_EQUIPMENT)"                UpdateCommand="UPDATE ServiceAgents SET AGENT=@AGENT, PHONE=@PHONE WHERE (STATE=@STATE and CITY=@CITY and AGENT=@old_AGENT and EQUIPMENT=@EQUIPMENT)"                DeleteCommand="DELETE FROM ServiceAgents WHERE (STATE=@STATE and CITY=@CITY and AGENT=@AGENT and EQUIPMENT=@EQUIPMENT)" >                                <UpdateParameters>                    <asp:Parameter Type="String" Name="AGENT" />                    <asp:Parameter Type="String" Name="PHONE" />                                         <asp:Parameter Name="old_AGENT" />                    <asp:Parameter Type="String" Name="STATE" />                    <asp:Parameter Type="String" Name="CITY" />                    <asp:Parameter Type="String" Name="EQUIPMENT" />                </UpdateParameters>                                <InsertParameters>                    <asp:ControlParameter Name="Ser_STATE" ControlID="TextBox_state"/>                    <asp:ControlParameter Name="Ser_CITY" ControlID="TextBox_city"/>                    <asp:ControlParameter Name="Ser_AGENT" ControlID="TextBox_agent"/>                    <asp:ControlParameter Name="Ser_PHONE" ControlID="TextBox_phone"/>                    <asp:ControlParameter Name="Ser_EQUIPMENT" ControlID="TextBox_equip" />                   </InsertParameters>                                <DeleteParameters>                   <asp:Parameter Type="String" Name="STATE" />                    <asp:Parameter Type="String" Name="CITY" />                    <asp:Parameter Type="String" Name="AGENT" />                    <asp:Parameter Type="String" Name="EQUIPMENT" />                </DeleteParameters>                            </asp:SqlDataSource>
Does anyone got any ideas about it? Where is wrong in the control?

View 3 Replies View Related

SqlDataSource && DetailsView UpdateCommand

Mar 6, 2006

Hi
I have a Page with a DetailsView and SqlDataSource. When Editing the DetailsView the Sql;DataSource UpdateCommand does not seem to pick up the @parameters of the form fields. I have used OnItemUpdating to view all Keys/OldValues/NewValues passed into the UpdateCommand but nothing seems to be picked up.
When I place a value into UpdateCommand it updates correctly but does not when I use the form. At this stage I have simplified the code down to typical Master-Details Pages (Separate) using a QueryString to filter the SelectCommand. But nothing seems to work.
Please help! I have wasted so much time trying to resolve this and I am on deadline and need this to work.
Thanks
Dave

View 3 Replies View Related

SQLDataSource: Update 2 Tables With 1 UpdateCommand?

Mar 16, 2007

I have a Gridview (edit enabled), connected to a SQLDataSource.
 SQLDataSource populates the gridview from 1 SelectCommand.
 figure1:
ColumnA | ColumnB | ColumnC
 
I have 2 SQL Server 2005 tables: Table1 and Table2 
Now on my SQLDataSource's UpdateCommand, I want the value of ColumnB to go to Table1's ColumnB, and ColumnC to go to Table2's ColumnC.
How do I do this?
I understand I can't do this with 1 UPDATE-SET sql query. Maybe I can with stored procs or something, but im kinda noobish when it comes to this. How? Thanks

View 1 Replies View Related

How To Programmatically Construct The UpdateCommand For SqlDataSource

Aug 1, 2007

Hi, All
I'm using Gridview and SqlDataSource to dynamically display the contents in different tables, as followed:
<%   dataSource.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["connectionString"];   dataSource.SelectCommand = "SELECT * FROM " + tableName;   gridView.DataBind();
   dataSource.UpdateCommand = "";%>
<asp:SqlDataSource ID="dataSource" runat="server"></asp:SqlDataSource><asp:GridView ID="gridView" runat="server" DataSourceID="dataSource" AllowPaging="True" AllowSorting="True" AutoGenerateEditButton="True" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" PageSize="20" DataKeyNames="ID" OnRowDataBound="tableGridView_RowDataBound">    <HeaderStyle BackColor="#C0C0FF" />    <AlternatingRowStyle BackColor="#C0FFC0" /></asp:GridView>
The datasource take the "tableName" as argument to determine which table to display. My problem is I can't figure out a way to programmatically construct the UpdataCommand for the SqlDataSource. I try to get the field names from the HeaderRow, but all the cells are empty in this row.
Does anyone know what causes the problem or how to construct the UpdateCommand properly. Thanks!

View 3 Replies View Related

GridView Update, With SqlDataSource UpdateCommand Set From Code-behind. (C#)

Mar 9, 2006

Hi all
I have a GridView on an aspx page, that is enabled for editing, deletion and sorting.
In the Page_Load event of the aspx page, i add a SqlDataSource to the page, and bind the source to the GridView.
When i click the update, or delete button, it makes a PostBack, but nothing is affected. I'm sure this has got something to do with the parameters.
First, i tried having the GridView.AutoGenerateColumns set to True. I have also tried adding the columns manually, but no affect here either.
The code for setting the commands, and adding the SqlDataSource to the page are as follows:
            string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;            string strProvider = ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName;            string selectCommand = "SELECT * FROM rammekategori";                        SqlDataSource ds = new SqlDataSource(strProvider, strConn, selectCommand);            ds.ID = "RammeKategoriDS";            ds.UpdateCommand = "UPDATE rammekategori SET Kategoribeskrivelse = @Kategoribeskrivelse WHERE (Kategorinavn = @Kategorinavn)";            ds.DeleteCommand = "DELETE FROM rammekategori WHERE (Kategorinavn = @Kategorinavn)";                        Parameter Kategorinavn = new Parameter("Kategorinavn", TypeCode.String);            Parameter Kategoribeskrivelse = new Parameter("Kategoribeskrivelse", TypeCode.String);            ds.UpdateParameters.Add(Kategorinavn);            ds.UpdateParameters.Add(Kategoribeskrivelse);            ds.DeleteParameters.Add(Kategorinavn);
            Page.Controls.Add(ds);
            SqlDataSource m_SqlDataSource = Page.FindControl("RammeKategoriDS") as SqlDataSource;
            if (m_SqlDataSource != null)            {                this.gvRammeKategorier.DataSourceID = m_SqlDataSource.ID;            }
As mentioned - no affect at all!
Thanks in advance - MartinHN
 

View 4 Replies View Related

SELECT A Single Row With One SqlDataSource, Then INSERT One Of The Fields Into Another SqlDataSource

Jul 23, 2007

What is the C# code I use to do this?
I'm guessing it should be fairly simple, as there is only one row selected. I just need to pull out a specific field from that row and then insert that value into a different SqlDataSource.

View 7 Replies View Related

Can't Insert New Data To Sql Using Sqldatasource.insert, Web Forms And A Master Page

Sep 11, 2006

Hello, I'm new to the forum and new to SQL, ASP.NET, etc.  I am creating an intranet site for my company in VS 2005 and have run into a very annoying problem that I can't seem to solve.  I have tried Googling it and came up empty.  I have a database in SQL Express 2005 and my website will be accessing several tables within the database.  I can retrieve info just fine and I can update, delete, etc just fine using gridview or other prebuilt tools, but when I add a few text boxes and wire a button to the SqlDataSource.Insert() command, I get a new record that is full of null values except for the identity key I have set.  The kicker is that I am also using a master page and when I duplicate the web page without the master page link, everything works just fine.  The following snippets show what I'm doing:<InsertParameters><asp:FormParameter Name="Name" Type="String" FormField="txtName" /><asp:FormParameter Name="Location" Type="String" FormField="ddlLocation" /><asp:FormParameter Name="Issue" Type="String" FormField="txtProblem" /></InsertParameters>Of course I match the formfields to the text boxes, create an onclick event for my button, the sqldatasource is configured correctly, it just doesn't work with the master page no matter what I do. Any help would be appreciated. Thanks

View 3 Replies View Related

Insert By SqlDataSource

Nov 13, 2007

Hi,I am trying to insert data using data from a datalist on the page. To do this, I use the following coding:        command.CommandText = "INSERT INTO Messages (sendername,recievername,message,Date,subject) VALUES (@sendername,@recievername,@message,@date,@subject)";        command.Parameters.AddWithValue("@sendername", System.Web.HttpContext.Current.User.Identity.Name);        command.Parameters.AddWithValue("@recievername", SqlDataSource2 );        command.Parameters.AddWithValue("@message", TextBox2.Text);        command.Parameters.AddWithValue("@subject", TextBox3.Text);        command.Parameters.AddWithValue("@date", DateTime.Now.ToString());        command.ExecuteNonQuery(); SqlDataSource is the datasource for the other datalist- will this work?Thanks,Jon 

View 11 Replies View Related

Sqldatasource.insert

Mar 27, 2008

how can I insert a record using variables?
So that
var1="Name1"
SqlDatasource1.Insert(var1)

View 5 Replies View Related

SqlDataSource.Insert()

Apr 24, 2008

Hi. I'm testing GridView and SqlDataSource controls and I'm using this http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insert.aspxI have problems with inserting new items into the db. As I understood from the code in that example, I need to create InsertParamaters and name it just like the one in the insert query. <asp:SqlDataSource ID="Sql1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"            SelectCommand="SELECT * FROM [Clients]" DeleteCommand="DELETE FROM [Clients] WHERE [ID] = @ID"            InsertCommand="INSERT INTO [Clients] ([Name]) VALUES (@Name)" UpdateCommand="UPDATE [Clients] SET [Name] = @Name WHERE [ID] = @ID">            <DeleteParameters>                <asp:Parameter Name="ID" Type="Int32" />            </DeleteParameters>            <InsertParameters>                <asp:ControlParameter Name="Name" ControlID="newClientTB" />            </InsertParameters>            <UpdateParameters>                <asp:Parameter Name="Name" Type="String" />                <asp:Parameter Name="ID" Type="Int32" />            </UpdateParameters>            <InsertParameters>                <asp:Parameter Name="Name" Type="String" />            </InsertParameters>        </asp:SqlDataSource> and I get the following error when run:The variable name '@Name' has already been declared. Variable names must be unique within a query batch or stored procedure. Any help? 

View 2 Replies View Related

Insert Into Two Tables Sqldatasource

Jun 30, 2006

Coming from an asp world, I am totally lost on this one.
I have two tables.
tblUsers and tblUserInfo
I have a gridview that gives me the list of users and when selected, it gives me the detailsview of the the record.  However, When I need to add a new user, I am trying to add that user into tblUsers (which happens with no problems), and then add a record, using the same user number (UserID) has the key or ID for the tblUserInfo.
So basicly, when I create a new user in tblUsers I want to create a record in tblUserInfo with the same userid.
In ASP, this takes me minutes... I have been trying to figure this out for weeks.
vs2005, sql express.
Thanks.

View 1 Replies View Related

Need Help In SqlDataSource.Insert(); I Keep Getting An Error!!

Jan 4, 2007

Hello there,
I made a page to add these fields (name, description, price, end_date) into a SQL database. I'm using ASP.NET 2.0 with C#, my database is SQL 2005.
I did it without DetailsView or FormView, it consists of TextBoxes and a Calendar. Anyways, i wrote this code for Button1, which is the button that adds the data.
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource sql = LoginView1.FindControl("SqlDataSource1") as SqlDataSource;
sql.Insert();
Response.Redirect("home.aspx");
}
The parameters and insert statments and commands are written from the SqlDataSource Insert Query wizard. But I keep getting this error when trying to click Button1.
Object must implement IConvertible.
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.InvalidCastException: Object must implement IConvertible.Source Error:




Line 31: {
Line 32: SqlDataSource sql = LoginView1.FindControl("SqlDataSource1") as SqlDataSource;
Line 33: sql.Insert();
Line 34: Response.Redirect("home.aspx");
Line 35: }
Source File: c:Documents and SettingsDoublethink..!!My DocumentsVisual Studio 2005WebSitesSunnDarkProjectsell.aspx.cs    Line: 33
 
Any ideas how to fix this?

View 4 Replies View Related

Insert Into Two Tables Via Sqldatasource

Feb 6, 2007

Hi, I have some problem with inserting data into two separate table which are connected via foreign key like in this example:Students (id_s, name, id_subject)Subjects (id_subject, name)So the point is to add a new student and subject for that chosen student. You have to make two inserts right? but how to pass the primary key to the table with foreign key? The form consists of three texbox: name, name_of_subject. Both id_s and id_subject are increment automatically. Any idea how to do it? I would be very grateful for the working code.Thanks in advance and best regards,N. 

View 5 Replies View Related

Executing Insert SQLdatasource

Apr 24, 2007

Hey forum,
the .NET form controls make it extremely easy to manage database data, control + SQLdatasource et voilĂ , its there.
i have a web form, and a SQLdatasource with an insert query with parameters (works perfectly, only the Date picker Lite textbox ID as parameter wont register, but i have a thread runnin on their forums for that). when i open the Query builder and execute the query it works! woot! but now, how can i make it execute on a button press? i tried with several commands, like SQLdatasource1.execute, and several other commands i searched (can post later, not behind my test environment with my tools/webpage at the moment). so what is the command to let the SQLdatasource execute it's query? it's all i need to know to make several forms, please ghelp me! :)
gr. michael

View 2 Replies View Related

Sqldatasource Multiple Insert

Oct 8, 2007

Hi all,
I have few insertions statements in one datasource insert command, which i use for my user creation process adding new billing info shipping info and so on.
I've put this code in createuserwizard usercreated step with a try catch code. On the insertion if it doesnt work it deletes the user account.
Well lets say the first insertion went trough with out any problems, but the second one got blocked or didnt work length or any wierd on controled issue.
I was thinking of putting begin transaction end transaction statements in front and end of the statements but this can prevent the insert not to return error, which will prevent try catch to fire?
Basicly the idea is to do all insertions with the user creation, and if one goes down all the others gets reversed. (if possible single sqldatasource, just to make the code look clean)

View 2 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 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

Odd Sqldatasource Insert Behavior

Jan 20, 2006

I have a sqldatasource (code listed below) whose insert Paramaters are control parameters.  My aspx page has a textbox and a submit button.  the button onclick runs the sqdatasource1.insert.
What I get is every other insert inserts the text in textbox2 and every other insert enters nothing for the namecust value.  I have a required field validator which correctly prevents submission if textbox2 is empty. 
How do I fix this?
:<code>
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="548px">
<asp:Button ID="Button1" runat="server" Text="New Prospect" ValidationGroup="insertCust" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox2"
ErrorMessage="Prospect Name can not be blank" ValidationGroup="insertCust"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox2" runat="server" Width="330px" ValidationGroup="insertCust"></asp:TextBox></asp:Panel>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AccPac2ConnectionString %>"
SelectCommand="SELECT DISTINCT CODETERR FROM dbo.F_arcus() AS F_arcus_1 WHERE (DATEINAC = 0) AND (rtrim(CODETERR) <>'')">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AccPac2ConnectionString %>"
InsertCommand="INSERT INTO dbo.BudgetProspects(NameCust, CodeTerr) VALUES (@Namecust, @codeterr)"
SelectCommand="SELECT CustomerID, NameCust FROM dbo.BudgetProspects WHERE (CodeTerr = @codeterr)"
UpdateCommand="UPDATE dbo.BudgetProspects SET NameCust = @namecust">
<UpdateParameters>
<asp:Parameter Name="namecust" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="RadioButtonList1" Name="codeterr" PropertyName="SelectedValue" />
</SelectParameters>
<InsertParameters>
<asp:ControlParameter ControlID="textbox2" Name="Namecust" PropertyName="text" />
<asp:ControlParameter ControlID="RadioButtonList1" Name="codeterr" PropertyName="SelectedValue" />
</InsertParameters>
</asp:SqlDataSource>
</code>
codebehind button_click:
<code>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not TextBox2.Text Is Nothing Then
SqlDataSource1.Insert()
TextBox2.Text = ""
End If
End Sub
</code>

View 1 Replies View Related

Problem With Insert Using SQLDataSource

Feb 6, 2006

I have a table with 2 columns - "memberid" is a guid and "Interest" is a string. In an aspx page I want to read in all values of "Interest" for a given "memberid" and display approprite checkboxes as checked. The user can then change which boxes are checked and I want to record the new list of selected items in the table. I created a SQLDataSource (see below) but when I run it, I get this error:
==========  Error  ===========
Disallowed implicit conversion from data type sql_variant to data type uniqueidentifier, table 'DB_136571.dbo.gs_MemberInterests', column 'memberid'. Use the CONVERT function to run this query.
============================
The only use of this SQLDataSource is to delete all entries for a given user and then insert an entry for each checked checkbox. The code to set the session variables is as follows:
========  Code  ============
Dim guidMemberid As Guid = CType(user.ProviderUserKey, Guid)
Session("currmember") = guidMemberid
.....
Session("currinterest") = CType(item.FindControl("CheckBox1"), CheckBox).Text
==========================
Any ideas of what I am doing wrong here?
 
========= SQLDataSource ==========
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:GoodSamSiteDB %>"
DeleteCommand="DELETE FROM [gs_MemberInterests] WHERE [memberid] = @memberid"
InsertCommand="INSERT INTO [gs_MemberInterests] ([memberid], [Interest]) VALUES (@memberid, @Interest)"
SelectCommand="SELECT memberid, Interest FROM gs_MemberInterests WHERE (memberid = @memberid) AND (Interest = @interest)">
<DeleteParameters>
<asp:Parameter Name="memberid" Type="Object" />
</DeleteParameters>
<SelectParameters>
<asp:SessionParameter Name="memberid" SessionField="currmember" Type="Object" />
<asp:SessionParameter Name="interest" SessionField="currinterest" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="memberid" Type="Object" />
<asp:Parameter Name="Interest" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
=============================

View 2 Replies View Related

DeleteCommand And UpdateCommand

Aug 1, 2006

I have added a gridview and under its properties i have changed AutoGenerateDeleteButton and AutoGenerateEditButton to true.
The problem is... when I try and delete a record, I get this error: Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified
If I try and update.. i get the error: Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.
Can someone please help me out... maybe with some code... or a link to a tutorial..
Thanks
Canning

View 18 Replies View Related

Have A Problem With UpdateCommand

Dec 28, 2006

Hello everyone,
 I am a bit new to ASP .Net so forgive me, if I dont understand something right off.
I am writing a page that gets code from the SQL database and puts it into a GridView. To get the information I am using SqlDataSource. I cant post an error message because I am running this off remote server but though testing I figure that it crashes when I add
Analysis = @Analysis
line into the UpdateCommand. First I thought that maybe my parameters were not read correcty but when I tried something like
Analysis  = 6
it worked. Then I tried to replace CQNo=@CQNo with
CQNo = @Analysis
and it also worked.
 I am very much puzzed at this. In SQL database CQNo is varchar, WorkDate is DateTime and Analysis is Money type.
 Can someone please help, I am out of ideas. Thanks!
<asp:SqlDataSource ID="myEfforts" runat="server"
SelectCommand="SELECT SNo, CQNo, WorkDate, Analysis, Design, Coding, Testing, DesRev, CodeRev, PeerRev, SysTest, PostInstall, Others, TotEff FROM Effort WHERE EmpId = @EmpId ORDER BY WorkDate DESC"
DeleteCommand="DELETE FROM Effort WHERE SNo=@SNo"
UpdateCommand="UPDATE Effort SET CQNo = @CQNo, WorkDate=@WorkDate Analysis=@Analysis WHERE SNo=@SNo">
<SelectParameters>
<asp:SessionParameter DefaultValue="" Name="EmpId" SessionField="PR_EmpIDVal" Type="String" />
</SelectParameters>

View 6 Replies View Related

Can I Use A Stored Procedure For INSERT In SqlDataSource?

Jun 20, 2006

Hello,
I have created a web page with a FormView that allows me to add and edit data in my database.  I configured the SqlDataSource control and it populated the SELECT, INSERT, UPDATE and DELETE statements.  I've created a stored procedure to do the INSERT and return to new identity value.  My question is this: Can I configure the control to use this stored procedure?  If so, how?  Or do I have to write some code for one of the event handlers (inserting, updating???)
Any help would be appreciated.
-brian

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

Sqldatasource And Formview Insert Problem

Aug 10, 2006

I m trying to INSERT a record to my Consultants table using sqldatasource and formview:
here is my sqldatasource code:
<asp:SqlDataSource ID="sqlDS1" runat="server" ConnectionString="<%$ ConnectionStrings:myDB %>"InsertCommand="INSERT INTO [Consultants] ([firstName],[lastName],[skillCategoryID],[resourceManagerID],[AMgroupID],[skillSet],[statusID],[location],[comments],[profile],[isAvailable],[dateModified],[focusID])
VALUES (@FNAME, @LASTNAME, 1, @RESOURCEMANAGERID, @AMGROUPID, @SKILLSET, @STATUSID, @LOCATION,@COMMENTS,@PROFILE,@ISAVAILABLE,getdate(),1)">

<InsertParameters>      <asp:FormParameter FormField="txtFName" Name="FNAME" />     <%--other parameters--%></InsertParameters></asp:SqlDataSource>
now in my formview i have this:<asp:FormView DefaultMode="Insert" ID="FormView1" runat="server" DataSourceID="sqlDS1" DataKeyNames="id">
<table border="0" cellspacing="5" cellpadding="0"><tr>  <td class="blacktextbold">First Name:</td>  <td class="blacktext"><asp:TextBox ID="txtFName" CssClass="txtfield" Width="200" runat="server" Text="<% #Bind('firstName')%>" /> <asp:RequiredFieldValidator ControlToValidate="txtFName" runat="server" ValidationGroup="gpInsert" ErrorMessage="Required Field" Display="Dynamic" CssClass="redtextsmallbold" /> </td></tr> </table>
THE PROBLEM:no matter what i put the txtFName field its ALWAYS null and i get INSERT error as column firstName cant accept NULLany ideas? ur help would be appreciated
 

View 4 Replies View Related

Sqldatasource INSERT Commander Errors

Sep 4, 2006

Ok, when i use a sqldatasource control and build a INSERT command like below.  My code always gives me a already have @UserId parameter error when I try to insert.  What am I doing wrong here? SqlDataSource INSERT COMMAND:INSERT INTO Ranger_Profile(UserId, FirstName, LastName, Address, City, State, Zip, HomePhone, CellPhone, Email) VALUES (@UserId, @FirstName, @LastName, @Address, @City, @State, @Zip, @HomePhone, @CellPhone, @Email)Page Code:Dim RangerProfileDataSource As SqlDataSource = SqlDataSource1RangerProfileDataSource.InsertParameters.Add("UserId", CreateNewUser.UserName.ToString)RangerProfileDataSource.InsertParameters.Add("FirstName", txtFirstName.Text.ToString)RangerProfileDataSource.InsertParameters.Add("LastName", txtLastName.Text.ToString)RangerProfileDataSource.InsertParameters.Add("Address", txtAddress.Text.ToString)RangerProfileDataSource.InsertParameters.Add("City", txtCity.Text.ToString)RangerProfileDataSource.InsertParameters.Add("State", txtState.Text.ToString)RangerProfileDataSource.InsertParameters.Add("Zip", txtZip.Text.ToString)RangerProfileDataSource.InsertParameters.Add("HomePhone", txtHomePhone.Text.ToString)RangerProfileDataSource.InsertParameters.Add("CellPhone", txtCellPhone.Text.ToString)RangerProfileDataSource.InsertParameters.Add("Email", CreateNewUser.Email.ToString)Dim rowsaffected As Integer = SqlDataSource1.InsertIf rowsaffected = 0 Then'End If

View 4 Replies View Related

Problem With SqlDataSource.Insert() Using MasterPage

Oct 23, 2006

Hi,because I have had problems with transporting of data from TextBoxes  to SQL database in my application using SqlDataSource.Insert(), I tried to analyze it using Microsoft's sample code located here: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insert.aspxEverything worked well untill I have used masterpage. Since this moment my database table started receive only NULL values - the same problem, which I have in my application. Despite all data values were correct before calling SqlDataSource.Insert() method. Is it some bug or something else (my bug ) and how can I resolve it? I'd like to use all advantages of masterpages and datasources together.Here are non-working codes of spoken sample:shelter3.aspx<%@ Page Language="VB" MasterPageFile="~/MasterPage3.master" AutoEventWireup="false" CodeFile="shelter3.aspx.vb" Inherits="shelter3" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="Obsah" runat="Server"><asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"DataTextField="nazev" DataValueField="code" /><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:intranet %>"SelectCommand="SELECT nazev,code FROM smenky" InsertCommand="INSERT INTO smenky (nazev,code) VALUES (@nazev,@code)"><InsertParameters><asp:FormParameter Name="nazev" FormField="NazevBox" /><asp:FormParameter Name="code" FormField="CodeBox" /></InsertParameters></asp:SqlDataSource><p><asp:TextBox ID="NazevBox" runat="server" /><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="NazevBox"Display="Static" ErrorMessage="Please enter a company name." /><p><asp:TextBox ID="CodeBox" runat="server" /><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="CodeBox"Display="Static" ErrorMessage="Please enter a phone number." /><p><asp:Button ID="Button1" runat="server" Text="Insert New Shipper" /></asp:Content> shelter3.aspx.vbPartial Class shelter3Inherits System.Web.UI.PageProtected Sub InsertShipper(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.ClickSqlDataSource1.Insert()End SubEnd Classmasterpage3.master<%@ Master Language="VB" CodeFile="MasterPage3.master.vb" Inherits="MasterPage3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"><title>Untitled Page</title></head><body><form id="form1" runat="server"><div><asp:contentplaceholder id="Obsah" runat="server"></asp:contentplaceholder></div></form></body></html>masterpage3.master.vbPartial Class MasterPage3Inherits System.Web.UI.MasterPageEnd ClassThanks for any idea

View 1 Replies View Related

SQLDatasource.Insert() Should Be Simple, But I'm Stuck!

Mar 30, 2007

Hi all, I really can't figure out what i'm doing wrong here, and I'd appreciate some help if possible please!   SqlDataSource5.InsertParameters("ntuser").DefaultValue = ntuser SqlDataSource5.InsertParameters("datetime").DefaultValue = DateTime.Now SqlDataSource5.Insert()Above is my code to insert into my SQL database a varchar NT user name, and the current date. The Parameters are defined in the HTML as :  <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:Test EnvironmentConnectionString %>" InsertCommand="usp_insert_hit" InsertCommandType="StoredProcedure" SelectCommand="usp_select_hits" SelectCommandType="StoredProcedure" UpdateCommand="usp_insert_hit" UpdateCommandType="StoredProcedure"> <InsertParameters> <asp:Parameter Name="ntuser" Type="String" /> <asp:Parameter Name="datetime" Type="DateTime" /> </InsertParameters></asp:SqlDataSource> My SQL Database is set up to have a table called "Hits" which has three colums, a hit_id (Autocounter, primary key), ntuser (varchar), datetime (datetime)  When the application runs it stops at runtime and highlights the SQLDataSource5.Insert() line, and I can't figure out why - can anyone else tell why please? thanks. 

View 1 Replies View Related

Insert Data With Parameters And Sqldatasource

Apr 24, 2007

I have a sqldatasource in a wizard. When I click the finishbutton in the wizard I want to insert some values (from textboxes, dropdownlists in my wizard) into a mysql-database. For this I use parameters, I add some values in the design mode and some in codebehind. The parameters in codebehind are added perfectly but the other parameters in designmode (name, email) just inserts null. Why?  My datasource: <asp:SqlDataSource
ID="dsInsert"
InsertCommand="INSERT INTO tbltest (name, email, city) VALUES (?name, ?email, ?city)"
runat="server"
ConnectionString="<%$ ConnectionStrings:conn %>"
ProviderName="MySql.Data.MySqlClient">
<InsertParameters>
<asp:FormParameter Name="?name" ConvertEmptyStringToNull="true" Type="string" FormField="name" />
<asp:FormParameter Name="?email" ConvertEmptyStringToNull="true" Type="string" FormField="email" />
</InsertParameters>
</asp:SqlDataSource>   The codebehind:         protected void finishButtonClick(object sender, EventArgs e)        {            dsInsert.InsertParameters.Add("?city", TypeCode.Int32, city.SelectedValue);            dsInsert.Insert();        }

View 3 Replies View Related

Help...pls Check What's Wrong....not Able To Do Insert With Sqldatasource

May 9, 2007

Hi frdz,         I m the new user of ASP.NET WEB APPLICATIONS WITH C# LANGUAGE.         I m using SQL SERVER 2005 and SQLDATASOURCE to get or retrieve the data from the database.         I have created the stored procedure for insert and update.         The stored procedure is executing fine when i m running it from sqlserver2005.         My problem is with the web-application page.         I m not able to insert or update data thru that...         Pls check the code and tell me what's missing out ..........SQLDATASOURCE<asp:SqlDataSource ID="srcemp" runat="server" ConnectionString="<%$ ConnectionStrings:empmaster  %>"     InsertCommand="empStoredProcedure" InsertCommandType="StoredProcedure"     UpdateCommand="empStoredProcedure" UpdateCommandType="StoredProcedure"      DeleteCommand="DELETE FROM empmaster          WHERE empid = @empid" DeleteCommandType="Text"     SelectCommand="select * from empmaster " SelectCommandType="Text">     <InsertParameters><asp:Parameter Name="empname" Type="String" /><asp:Parameter Name="address" Type="String" /><asp:Parameter Name="city"  /><asp:Parameter Name="pincode" /><asp:Parameter Name="state" /></InsertParameters> <UpdateParameters><asp:Parameter Name="empname" Type="String" /><asp:Parameter Name="address" Type="String" /><asp:Parameter Name="city"  /><asp:Parameter Name="pincode" /><asp:Parameter Name="state" /></UpdateParameters>     </asp:SqlDataSource>GRIDVIEW  <asp:GridView ID="empGridView" runat="server" AutoGenerateColumns="False"         DataKeyNames="empid" DataSourceID="srcemp"         Width="56px" >             <Columns>    <asp:TemplateField>    <ItemTemplate>    <asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this row ?');">Delete</asp:LinkButton>    </ItemTemplate>    </asp:TemplateField>                                                  <asp:boundfield datafield="empname"            headertext="emp Name"/>           <asp:boundfield datafield="address"            headertext="Address"/>          <asp:boundfield datafield="city"            headertext="City"/>         <asp:boundfield datafield="state"            headertext="State"/>                                     <asp:CheckBoxField            DataField="deleted"            HeaderText="In Existance" />            </Columns>          </asp:GridView>C# code protected void cmdsubmit_Click(object sender, EventArgs e)    {        srcemp.InsertParameters["empname"].DefaultValue = tbcompanyname.Text;        srcemp.InsertParameters["address"].DefaultValue = tbaddress.Text;         srcemp.InsertParameters["city"].DefaultValue = tbcity.Text;        srcemp.InsertParameters["pincode"].DefaultValue = tbpincode.Text;        srcemp.InsertParameters["state"].DefaultValue = cmbstate.SelectedItem.ToString();         srcemp.Insert();}Note :I m not getting a single error msg for the above code in web-page or stored procedure but it does not insert,update or delete the record from the database....Thanxs in adv...pls reply at earliest if possible...What's missing ??can anyone check out..what's wrong ??

View 1 Replies View Related

Getting The Automatically Generated Id After SqlDataSource.Insert()

Aug 24, 2007

Hello! I have a SqlDataSource that inserts some data in a database. The field "id" is auto-increment. Is it possible to use the "id", this data-row got from the database automatically, directly after the SqlDataSource.Insert() command in my CodeBehind file? Thank you! 

View 13 Replies View Related







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