Variable Insert to SQL server insert satement setting values for the @variable INSIDE sql

ok, I am on Day 2 of being brain dead.

I have a database with a table with 2 varchar(25) columns 

I have a btton click event that gets the value of the userName,  and a text box.

I NEED to insert a new row in a sql database, with the 2 variables.

Ive used a sqldatasource object, and tried to midify the insert parameters, tried to set it at the button click event, and NOTHING is working.

 

Anyone have a good source for sql 101/ASP.Net/Braindead where I can find this out, or better yet, give me an example.

 this is what I got

 

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

 

    protected void runit_Click(object sender, EventArgs e)
    {
       //SqlDataSource ID = "InsertExtraInfo".Insert();
      //SqlDataSource1.Insert();
    }

 

 

    protected void Button1_Click1(object sender, EventArgs e)
    {

        SqlDataSource newsql;
       
        newsql.InsertParameters.Add("@name", "Dan");
        newsql.InsertParameters.Add("@color", "rose");
        String t_c = "purple";
        string tempname = Page.User.Identity.Name;
        Label1.Text = tempname;
        Label2.Text = t_c;
        newsql.Insert();
    }


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>mini update</title>
</head>
<body>
    <form id="form1" runat="server">
        &nbsp;name<asp:TextBox ID="name" runat="server" OnTextChanged="TextBox2_TextChanged"></asp:TextBox><br />
        color
        <asp:TextBox ID="color" runat="server"></asp:TextBox><br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" />
        &nbsp;<br />
        set lable =&gt;<asp:Label ID="Label1" runat="server" Text="Label" Width="135px" Visible="False"></asp:Label><br />
        Lable 2 =&gt;
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
        Usernmae=&gt;<asp:LoginName ID="LoginName1" runat="server" />
        <br />
        <br />
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
            ConnectionString="<%$ ConnectionStrings:newstring %>" DeleteCommand="DELETE FROM [favcolor] WHERE [name] = @original_name AND [color] = @original_color"
            InsertCommand="INSERT INTO [favcolor] ([name], [color]) VALUES (@name, @color)"
            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [name], [color] FROM [favcolor]"
            UpdateCommand="UPDATE [favcolor] SET [color] = @color WHERE [name] = @original_name AND [color] = @original_color">
            <DeleteParameters>
                <asp:Parameter Name="original_name" Type="String" />
                <asp:Parameter Name="original_color" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="color" Type="String" />
                <asp:Parameter Name="original_name" Type="String" />
                <asp:Parameter Name="original_color" Type="String" />
            </UpdateParameters>
            <InsertParameters>
        <asp:InsertParameter("@name", "Dan", Type="String" />
        <asp:InsertParameter("@color", "rose") Type="String"/>
          
               
            </InsertParameters>
        </asp:SqlDataSource>
        &nbsp;
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataKeyNames="name" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
               
                <asp:BoundField DataField="color" HeaderText="color" SortExpression="color" />
                <asp:BoundField DataField="name" HeaderText="name" ReadOnly="True" SortExpression="name" />
            </Columns>
        </asp:GridView>
      
    </form>
</body>
</html>

 

0
Harperator
4/29/2007 2:15:40 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

1 Replies
874 Views

Similar Articles

[PageSpeed] 56

Sorry about the messy code above, but I think I solved PART of my problem.

To set the variable @name, I went to the properties of the sqlDataSource, and clicked the [...] key and set the Parameter Source to PROFILE then set the  value of name to PropertyName="UserName  So the tag just looks like <asp:ProfileParameter Name="name" PropertyName="UserName" />

I still dont know how to set a sql statement's "@varieble" from putside the insert statement.,Any thoughts?

 


 

0
Harperator
4/29/2007 2:51:11 PM
Reply:

Similar Artilces:

SQL Server insert query
When I am inserting into a table, I have some values which I am finding are "N/A" which obviously come from a source which allows it ie nvarchar column)  I need to check the values before entering into the column, and if it is not an integer, converting it to the value '00000000' ie a similar thing would be isnull(columnname,00000000), but in this case, not checking for if it is null, but rather if it is an integer. Does anyone have any ideas? Take a look at http://berezniker.com/content/pages/sql/microsoft-sql-server/isnumericex-udf-data-type-awareBeware of ...

INSERT variable on SQL Server
Doing long nr1, ix ....Some Code for setting nr1, ix... INSERT INTO TableXY( anyrow1, anyrow2 ) SELECT :nr1 AS newnr1, anyrow2 FROM TableXY WHERE TableXY.anyrow1 = :ix USING SQLCA; brings me an (MS-SQL) ODBC-Error 37000 Syntaxerror... But, when I replace :nr1 in line 2 of the statement with a number e.g. 1181 like following: long nr1, ix ....Some Code for setting nr1, ix... INSERT INTO TableXY( anyrow1, anyrow2 ) SELECT 1181 AS newnr1, anyrow2 FROM TableXY WHERE TableXY.anyrow1 = :ix USING SQLCA; works fine! Both works fine when connecte...

how do i insert data into sql server using data from textboxes and sql connection and sql command
anyone can give me a simple explaination and code.. Thanx in advance Take a look @ Sample Code: How to add...Sushila Bowalekar PatelVisual ASP/ASP.NET MVPhttp://weblogs.asp.net/sushilasb There are a lot of tutorials out there, but I know they can be a bit confusing as they all approach things slightly differently. Basically a nice simple version would go like this:' *** First set up your connectionDim conConnection As New SqlConnection("server=servername;database=yourdatabase;uid=yourname;pwd=yourpassword;")' *** This line takes care of your sommand text and command connection in one ...

How do i insert the insert of a variable into a table (SQL Query Syntax)
Hello. My English may be a bit buggy, but i'll try to explain my question.I need to insert into a database the value of a textbox. I use a variable to read the contents of the textbox. Only problem is i don't know the proper SQL Syntax to insert that variable into the table. (INSERT INTO tablename (field1,field2) VALUES (???). Thanks. Hi, please take a look at this page: Inserting into a table Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Workaround for non working Mark as answer buttons....

Timestamp variable in SQL server 2005 and SQL server express editions!!! Help!!!!
Hi, Can anyone update me whether the 'timestamp' datatype has been changed in the recent release of sql server 2005 or sql server express?? In previous versions it is generating a unique number or row version...it was told that they will be updating 'timestamp' variable to contain the value of current datetime as the word 'timestamp' actually means. Please let me know.. Thanks.. ...

INSERT a variable into sql
Hello, i have a connection to a mssql and i try to add login information from registration form to db. to be specified just a username. I have my usernamy in string variable login. Now i'm trying to put this in sql querry: InsertCommand="INSERT INTO [Klients] ([Surname], [name], [login]) VALUES (@Surneame, @name, login)" But this is not going thruogh. Help. You can use Command.Parameters.Add() to assign your variable to sql statement.InsertCommand.CommandText = "INSERT INTO [Klients] ([Surname], [name], [login]) VALUES (@Surneame, @name, @login)";InsertCommand.Parameters.Add("@Surn...

Timestamp variable in SQL server 2005 and SQL server express editions!!! Help!!!! #2
Hi, Can anyone update me whether the 'timestamp' datatype has been changed in the recent release of sql server 2005 or sql server express?? In previous versions it is generating a unique number or row version...it was told that they will be updating 'timestamp' variable to contain the value of current datetime as the word 'timestamp' actually means. Please let me know.. Thanks.. ...

Insert SQL on Sql Command
i'm using an sql command for insert query it looks like this cmd=new sqlcommand("insert into tblname values('" & textbox1.text & "')",cn) cmd.executereader the problem is if i type a singlequote or double quote an error is throwing,invalid syntax .... how can i s'rt out it with out using a sql stored procedure thanks in advance PrasantHI think therefore i'mvPrasĀ© Hi, try replacing the single quotes present in your input with double single quotes ... example below: string sqlInput = textbox1.text.Replace("'","''...

Inserting SQL statements into a SQL Server 2000 database
Hi all Am attempting to create an audit table that will allow me to keep tracke of who is doing what where and when. On thing that i want to insert into this table, is the actual command that was executed, however when i look at the data that i inserted all that i get is "System.Data.SqlClient.SqlCommand" in the field. Any suggestion on how to overcome this problem. Mike55 Hello Mike55 if I understand you right, you like to record each request to have the possibility to control who do what and when. I think a good possibility is to create a httphandler to record all...

Using Linq to SQL to insert into an SQL Server XML column
I'm getting an error on this line: ' auditData.PCAuditDataXML = Xdoc.Element("Model") 'Can anyone see where I'm going wrong here?    Private Sub insertDataIntoAuditDataTable(ByVal userName As String, ByVal computerName As String, ByVal Xdoc As XDocument)        Dim ADDC As AuditDataDataClassesDataContext = New AuditDataDataClassesDataContext        Try            Dim auditData As New AuditData_ad     ...

sql server 2005 inserting prbblem..wrong SQL? wrong parameter?
Im trying to insert a record in my sql server 2005 express database.The following function tries that and without an error returns true.However, no data is inserted into the database...Im not sure whether my insert statement is correct: I saw other example with syntax: insert into table values(@value1,@value2)....so not sure about thatAlso, I havent defined the parameter type (eg varchar) but I reckoned that could not make the difference....Here's my code:        Function CreateNewUser(ByVal UserName As String, ByVal Password As String, _&nbs...

Sql Types
SQL Server 2000, ASP.Net 1.1 I've been writing this stuff for a while, and can't seem to come to the conclusion of how I should be retrieving data and assigning this data to variables. Since i'm using SQL Server, I'm convinced that I should be using the datareaders GetSqlDouble (or whatever) function, but this would mean i need my local variables to be one of the SQL types.  The problem with that is, that there will have to be lots of conversions done by me to be able to use a SQL type in my application. For instance, I have a class where i'm retrieving dates.  In or...

SQL A and SQL Server
Hi I heard SQL Server used to be owned by Watcom is this true? Is SQL Anywhere, therefore, similar to SQL Server? -- Regards, John Not quite true. SQL Anywhere was created by Watcom. SQLServer was created by Sybase, and Microsoft licensed the technology. So MSSQL and ASE have common roots, not SQLAnywhere. -- Paul Horan[TeamSybase] "John Kingan" <john.kingan@abibuildingdata.com> wrote in message news:40d82aa1$1@forums-1-dub... > Hi I heard SQL Server used to be owned by Watcom is this true? Is SQL > Anywhere, therefore, similar to SQL Ser...

Error using OdbcDataReader.ExecuteReader and Parameters...ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable
This seems to be a common problem but I have not seen any answers yet on this board.   I am porting over to using odbc because I have no choice with my Hosting company,  I was using basically the same code with the SQLDataReader and SQLCommand object and it was fine.  The below code will generate the error.  Help !! Unexpected exception: ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@Role'.. string sql = String.Empty ;sql = "Select * from Associate where Role=@Role and Exit_Date > @Exit_Date";string connString = getConn...

Web resources about - Variable Insert to SQL server insert satement setting values for the @variable INSIDE sql - asp.net.sql-datasource

Resources last updated: 12/27/2015 4:30:08 PM