0

I have this programming code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:IngBergConnectionString1 %>" 
            InsertCommand="INSERT INTO Table1(namn, development, roll, musik) VALUES (@namn,@development,@roll,@musik)" >
            <InsertParameters>
                <asp:Parameter Name="namn" Type="String" />
                <asp:Parameter Name="development" Type="String" />
                <asp:Parameter Name="roll" Type="String" />
                <asp:Parameter Name="musik" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>

But I can't connect up TextBoxes with Parameters. Which could be solution to this situation?
Thanks.

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Acrotab
0

I have this programming code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:IngBergConnectionString1 %>" 
            InsertCommand="INSERT INTO Table1(namn, development, roll, musik) VALUES (@namn,@development,@roll,@musik)" >
            <InsertParameters>
                <asp:Parameter Name="namn" Type="String" />
                <asp:Parameter Name="development" Type="String" />
                <asp:Parameter Name="roll" Type="String" />
                <asp:Parameter Name="musik" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>

But I can't connect up TextBoxes with Parameters. Which could be solution to this situation?
Thanks.

Solution is

protected void Button1_Click(object sender, EventArgs e)
{
    using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"))
    {
        SqlCommand CmdSql = new SqlCommand("INSERT INTO [Movies] (ID, Name, Genre, Length, Year, Description) VALUES (@ID, @Name, @Genre, @Length, @Year, @Description)", conn);
        conn.Open();
        CmdSql.Parameters.AddWithValue("@ID", TextBox1.Text);
        CmdSql.Parameters.AddWithValue("@Name", TextBox2.Text);
        CmdSql.Parameters.AddWithValue("@Genre", TextBox3.Text);
        CmdSql.Parameters.AddWithValue("@Length", TextBox4.Text);
        CmdSql.Parameters.AddWithValue("@Year", TextBox5.Text);
        CmdSql.Parameters.AddWithValue("@Description", TextBox6.Text);
        CmdSql.ExecuteNonQuery();
        conn.Close();
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.