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
ADVERTISEMENT
Aug 23, 2004
hey all,
I've posted about this before so apologies to anyone who read it the first time.
I want to have an ID column in my table, but I want the automatically generated number to have a prefix such as ABC. I'd also like to be able to change this prefix from an asp page depending on what is selected from a drop down.
Is any of this possible? I'd really appreciate a reply, even if it's to say this can't be done. Thanks
View 2 Replies
View Related
Mar 28, 2007
Hi,
I've created a stored procedure that creates a script to create a number of objects within the database (based on what existing objects are in the database). From Management Studio, this works fine, and the output is exactly as I want it.
I'm now trying to create a job that will execute this stored procedure, and deposit the results into a file somewhere on the server. When the job runs, the script is created in the correct place and is essentially ok.
However, there are a couple of questions I'd like to ask.
Why does SQL Server Agent put a header at the top of the output file? I was hoping to be able to use that output file 'as is' and execute it automatically to recreate my objects when required. (Obviously, I can manually remove the header, but this is an inconvenience in this situation). How do I stop it?
Also, when executed from SSMS, the output is correctly line-spaced. But, the output from the scheduled job adds an extra line between each line of text, which is, again, inconvenient. Why does it do this, and how can I prevent this (again, without manually editting the output)?
Any thoughts and help greatly appreciated.
Cheers
Simon
View 8 Replies
View Related
Jan 6, 2006
Hi,
This is my problem :
I have listBox1, listBox2 controls bound to sqldatasource1 and sqldatasource2.
I wrote one stored procedure to retrieve data from my sql database like :
select Id, Name,Address,Amount from KalakaDB
Now I want my listBox1 to display Name By name and my listBox2 to display Amount by decrease order
how can i connect my sqldatacontrol to the stored procedure ?
Thanks
View 1 Replies
View Related
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
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
Feb 7, 2006
Hi AllI have just upgraded to SQL2005 and found an annoying problem. WheneverI add a new view or amend an existing one (created in SQL 2000Enterprise Manager) it inserts TOP 100 Percent into the SQL query. Evenif I delete the clause from the SQL query it puts it straight back inagain. This is a problem as there are some queries where I just don'twant this clause there (ADO.NET cannot update a view with a TOP clause)Any ideas anyone?Many thanksIan Bell*** Sent via Developersdex http://www.developersdex.com ***
View 3 Replies
View Related
Jul 12, 2005
I'm trying to update (increment)
Company.SumtotalLogons
from CompanyUsers.NumberOfLogons
where CompanyUsers.CompanyID = Company.CompanyID
I'd like to either write a formula (if it is even possible to fire a formula from one table update/insert to increment a field in another table), or a stored procedure that triggers an auto update/append into Company.SumTotalLogons
I know this is possible in access, so i'm wondering how to go about it in ms-sql?
any ideas?
View 1 Replies
View Related
Jul 11, 2012
I want insert automatically records for Range that user definded
For example user define :
from to city
10000 12000 tehran
15000 19000 babol
I should inserted 2000 record for tehran (10000,10001,....,12000) and 4000 record for babol (15000,15001,...,19000)
View 3 Replies
View Related
Jul 18, 2007
Hi again all,
Is there a way to read a file name automatically from a network folder? I can successfully bulk insert from this particular folder. The next step is as I add files, I wish to bulk insert the latest file added so the program must make that determination and import that specific file. I can delete the older files if necessary and save them elsewhere but it would still be nice to be able to read the file name. I then wish to store the name of this file, whatever it is, into a field called "SourceFileName" in my table that I am bulk inserting into. Does anyone have an example in dynamic SQL? Thanks.
ddave
View 1 Replies
View Related
Jun 10, 2014
How to create insert statements of the data from a table for top 'n' rows. I know we can create using generate scripts wizard, but we can't customize the number of rows. In my scenario i got a database with 10 tables where every table got millions of records, but the requirement is to sample out only top 10000 records from each table.
I am planning to generate table CREATE statements from GENERATE Scripts wizard and add this INSERT STATEMENT at the bottom.
EX : INSERT [dbo].[table] ([SERIALID], [BATCHID] VALUES (126751, '9100278GC4PM1', )
View 4 Replies
View Related
May 27, 2007
I have one stored procedure for insert, update and delete operations, I need automatically logged the insert,update and delete operations.
How can I set auto logged mechanism and how can I access the logs in c#?
Thanks
View 1 Replies
View Related
May 23, 2008
Hello
I tried the Beta 1 of the service pack 1 to .net 3.5. If I try to add an entity (and try to save this), I get the Exception "No support for server-generated keys and server-generated values".
How can I add entities to my Sqlce- database?
I tried to give the id- column (primary key) in the database an identity, another time without identity, only primary key --> none of them worked. I always get the same error.
What do I have to change to make successfully a SaveChanges()?
Thanks for your help,
Gerald
View 21 Replies
View Related
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
Mar 27, 2008
how can I insert a record using variables?
So that
var1="Name1"
SqlDatasource1.Insert(var1)
View 5 Replies
View Related
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
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
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
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
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
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
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
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
View Related
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
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
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
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
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
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
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
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
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
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