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


ADVERTISEMENT

How Do I Insert Datagridr Checkbox Into SQL Bit Fields Using A SqlDataSource

Apr 13, 2006

Dim strStatus As String
Dim strGroup As String
Dim strLicense As String = dtgPhysician.DataKeys(e.Item.ItemIndex)
Dim strUpdateStatus As String
Dim strUpdateGroup As String
Dim strName As String
Dim strDate As String
Dim strSubject As String
Dim blPDA As Boolean
Dim strPDA As Byte
strStatus = CType(e.Item.FindControl("lstStatus"), DropDownList).SelectedItem.Text
strGroup = CType(e.Item.FindControl("txtGroup"), TextBox).Text
strName = e.Item.Cells(1).Text.Trim
strDate = CType(e.Item.FindControl("txtDate"), TextBox).Text
strSubject = CType(e.Item.FindControl("dpTraining"), DropDownList).SelectedItem.Text
blPDA = CType(e.Item.FindControl("ckPDA"), CheckBox).Checked
strPDA = Convert.ToString(blPDA)

strUpdateStatus = "UPDATE DoctorMaster SET Status = @p_Status , PGroup=@p_Group , @p_PDA wHERE (PLIC= @p_License);"
' ... Make a SQL call to update the database ...
'UpdatePhysician
Dim strConn As String
strConn = ConfigurationSettings.AppSettings("ConString")
If strConn = String.Empty Then
myConn = New SqlConnection()
Else
myConn = New SqlConnection(strConn)
End If
myConn.Open()
Dim daPhysician As New SqlDataAdapter()
Dim comUpdate As New SqlCommand()
comUpdate.Connection = myConn
daPhysician.UpdateCommand = comUpdate
comUpdate.CommandType = CommandType.Text
comUpdate.CommandText = strUpdateStatus
'Return the DataGrid to its pre-editing state
comUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@p_Status", System.Data.SqlDbType.Char, 3, "Status")).Value = strStatus
comUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@p_Group", System.Data.SqlDbType.NVarChar, 15, "PGroup")).Value = strGroup
comUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@p_License", System.Data.SqlDbType.NVarChar, 15, "PLIC")).Value = strLicense
 
comUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@p_PDA", System.Data.SqlDbType.Bit, "PDA")).Value = CType(e.Item.FindControl("ckPDA"), CheckBox).Checked.ToString

comUpdate.ExecuteNonQuery()

comUpdate.Dispose()
 
Thanks.
It kept givimg me data  format error.

View 1 Replies View Related

Using SQLDataSource To Insert And Select Data

Dec 12, 2007

I'm a traditional asp guy and I'm having a heck of a time getting my arms around this SQLDataSource provided in ASP.NET 2.0
I've setup the Connection String and successfully used the SQLDataSource.Insert method. 
I can't for the life of me figure out how to use the SQLDataSource.Select command. 
I want to get the @@IDENTITY of the last record inserted. 
Example:
---Works Fine---
SQLDataSource.InsertCommand = "Insert into Engines(Type, Description)values('" & DrpType.Text & "', '" & txtDescription.Text & "')"
SQLDataSource.Insert()
--- End Works Fine------- Doesn't Work---
SQLDataSource.SelectCommand = "Select @@IDENTITY as 'Identity'"    
set RecordSetVar = SQLDataSource.Select <--- this wants some kind of arguements
--- End Doesn't Work---
 

View 1 Replies View Related

SqlDataSource Select From One Table And Insert To Another

Mar 13, 2008

Is it possible within a Sqldatasource to select data from one database table and the insert that data into another?
eg:
 1 <asp:SqlDataSource ID="SqlDataSource" runat="server"
2 ConnectionString="<% Something %>"
3 InsertCommand="INSERT INTO [Resumes] ([ResumeID], [UserID], [CompanyID], [ResumeTitle], [ResumeDesc]) VALUES (@ResumeID, @UserID, @CompanyID, @ResumeTitle, @ResumeDesc)"
4 SelectCommand="SELECT [UserId], [CompanyID], [CompanyName] FROM [Info] WHERE ([UserId] = @UserId)" <SelectParameters>
5 <skm:MembershipUserIdParameter Name="UserId" />
7 </SelectParameters>
8 <InsertParameters>
9 <skm:MembershipUserIdParameter Name="UserId" />
10 <asp:Parameter Name="CompanyID" Type="Int32" />
11 <asp:Parameter Name="ResumeTitle" Type="String" />
12 <asp:Parameter Name="ResumeDesc" Type="String" />
13 </InsertParameters>
14 </asp:SqlDataSource>
  

View 1 Replies View Related

My SQLDataSource Select/Update/Insert/Delete

Jan 18, 2008

hi
i have form view that retrieves a single row
i dont want to use SQLDataSource default Select/Update/Insert/Delete buttons
i am using Stored Procedures
I want to have my own buttons, the select has parameters, how to retrieve data for that parameter?
 

View 6 Replies View Related

Single Value Of SqlDataSource

Jul 5, 2006

I have set up a sqlDataSource that returns one value.
I would like to assign the value to a string.
How would I acomplish this,
 
thanks

View 5 Replies View Related

Getting A Single Value From SqlDataSource

Mar 5, 2007

Hi,
I have a SqlDataSource(named SQLDS1) which retrieves 4 value from database(ProductName,ProductCost,ProductID). I Have a DropDownList(DDL1) control and its DataSource SQLDS1.
DDL1 Selected data field to display is ProductNameDDL1 Selected data field to value is ProductCost
I did all this in Visual Part without any line of code. But in the code behind , When i select an item from DDL1 i need its ProductName,ProductCost and Also ProductID. It is simple to get first two. But how can i get the ProductID. Is there anyway to get ProductID from SQLDS1.
Happy Coding

View 1 Replies View Related

How To Access SqlDataSource Fields From Code?

Aug 18, 2007

I have <asp:SqlDataSource> in aspx page that is being used by an updateable GridView.  However, there are a couple fields in the dataset that contain filenames that I want to access directly in code and place them into some image tags on the page. This line should give me access to the dataset but how to I access the fields?
Dim myDataSource As DataView = DirectCast(SqlDataSourceGridView.[Select](DataSourceSelectArguments.Empty), DataView)
When the SqlDataSource is a DataReader I would access it with the code below but since this SqlDataSource is a DataSet I can't access it with this code.If myDataSource.Read Then   If Convert.IsDBNull(myDataSource("CusAgentPhoto")) Then      ImageAgent.ImageUrl = "/photos/nophoto.gif"   Else      ImageAgent.ImageUrl = AgentImagePath & myDataSource("CusAgentPhoto").ToString   End If   If Convert.IsDBNull(myDataSource("CusCompanyLogo")) Then      ImageCompany.ImageUrl = "/photos/nophoto.gif"   Else       ImageCompany.ImageUrl = OfficeImagePath & myDataSource("CusCompanyLogo").ToString   End IfEnd If What would be the correct way to get at the DataSet fields that contain the filenames?

View 2 Replies View Related

UniqueIdentifier Fields As Parameters For SQLDataSource

Mar 7, 2006

Whn I use a UniqueIdentifier field as a parameter for SQLDataSource the parameter type defaults as an object. I just want to use the string value of the field.How do I do this?Thanks.

View 7 Replies View Related

How To Retrive Single Data From Sqldatasource Control

Aug 19, 2006

hi,

i need to code for retrieving single data from sqldatasource control. i need the full set of coding

connecting
retrieving data in text box
editing data to the table
updating data to the table
deleting data to the table

i want to fetch "single field data"

any one who know the code please post reply or send it to my mail senthilonline_foryou@rediffmail.com

View 1 Replies View Related

How To Retriece Single Record In Database By Using SqlDataSource???

Jun 19, 2007

Is me again,and now i facing problem to retrieve a single record from the database.
here is my code:
 
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim user As String        user = TextBox1.Text        Dim varpassword        Dim mydata As SqlDataSource
        mydata.SelectCommand = "Select * from tbluser where uLogin = '" & user & "'"        varpassword = mydata.SelectCommand.uPassword
    End SubEnd Class
 
but i get the error : 'uPassword' is not a member of 'String'
i wan to retrieve the password of that user,can anyone help me?
thanks

View 3 Replies View Related

Bind Individual Controls To A Single SqlDataSource

May 9, 2008

hello friends iam newlly joined in to company any one can help me how to bind individual controls to a single SqlDataSource Control..
my problem is "i have different text boxes and dropdown boxes and what i want to do is if i enter primary ker field(employeeno) in the text box automatically i need to get that particular record and i need to populate it to the Respective controls...
is there any chance of doing this by using a single datasource control..
 
pls help me its urgent
Regards
k.seshu

View 3 Replies View Related

Read Single Piece Of Data From SqlDataSource To A Variable?

Jan 17, 2006

First I want to say thanks to the folks how have helped me over the past week or two.
I'm missing a crucial piece of insight. How do I read a single piece of data from a SqlDataSource which only hold one row of data into a declared variable?
string zUserName = SqlDataSource.(get the value in the row that is labeled UserName)
It really doesn't matter to me whether it is an SqlDataSource or some other data container that hold the data I've selected. My goal is to be able to read some data from some predefined datasource into a declared variable.
If I am approaching this problem in the wrong way any advice or article links you could give me would be grealy appreciate.
Thanks, Bill

View 1 Replies View Related

How To Pull Data Into A Datagrid From The Same Table, 2 Fields, And Display Them As 1 Field In The SqlDataSource?

Jan 9, 2008

Hi, Im trying to pull data from 2 fields in the same table into a SqlDataSource that feeds into a GridView, and display them as 1 field in GridView? I have a database table that has entries of users and their friends. so
this tblFriendUser has a column called UserName and another column
called FriendUserName.
I am trying to get a list of friends for that particular user. Note
that if User1 initiated the friend request, he will be listed as
UserName and his friend as FriendUserName, but if his friend initiated
the friend request, it will be vice versa: him being the FriendUserName
and his friend the UserName. So I want the following 2 queries run and merged into
one query in order to return 2 columns only: UserFriendID & UserName, is that
possible? Is my design bad? Any suggestions/advice would help! Thanks a lot!


SELECT UserFriendID, UserName
FROM tblUserFriends
WHERE (UserName = @UserName);

SELECT UserFriendID, FriendUserName AS UserName
FROM tblUserFriends
WHERE (FriendUserName= @UserName);

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

Individual SqlDataSource() Or Common SqlDataSource() ?

Mar 8, 2007

i am using visual web developer 2005 with SQL Express 2005 with VB as the code behindi have one database and three tables in itfor manipulating each table i am using separate SqlDataSource() is it sufficient to use one SqlDataSource() for manipulating all the three tables ? i am manipulating all the tables in the same page only please help me

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

Sqldatasource Select Statement

Mar 27, 2007

Hi all,I drag sqldatasource to my form, and then adding a button there. I want when clicking the button to be able to use the sqldatasource1.select statement . I found some parameters that this method used but still dont know how to figure it out, which was IEnumerable Select (DataSourceSelectArguments a)for example when the button it clicked I want to perform the select * from employee Thanks

View 1 Replies View Related

How Do I Use A Value Returned From SQLDataSource Select?

Mar 28, 2007

I would like to use the value returned from my SqlDataSource SELECT method, in the INSERT method for the same SqlDataSource.
 Any ideas how this is done?

View 1 Replies View Related

If SqlDataSource.Select = Empty Then...?

May 28, 2007

(Newbie). I'm trying to: 1) check if the SELECT command has returned any records, and 2) put a msg box on the screen if there are no records returned from the SELECT query.  The type of code I'm heading towards is:  (but it's wrong). Thank you in advance for your C# code suggestion.
 protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{if (SqlDataSource1.SelectParameters.Contains is "") then
MessageBox.show ("There are no records available") ;
}

View 8 Replies View Related

SqlDataSource + Parameter + SELECT IN

Jul 20, 2007

I'm sure that is really simple, but how do I pass a parameter with multiple value to a SQLdatasource?
ex: SELECT field1 from tblTableA where idTableA IN ( @Param1)
 Let's say I want to pass 1,2,3,4  as Param1   (SELECT field1 from tblTableA where idTableA IN ( 1,2,3,4))
How I am supposed tu use the .SelectParameters.Add()  to pass a list of integers instead of  a single value??
Thanks in advance.

View 2 Replies View Related







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