locked
Ca't insert textboxes values into a database table RRS feed

  • Question

  • User528730340 posted

    Hi,

    I am also attempting to store data into a database from a textbox on a webform.

    The problem is there is an error with the provider. 

    Keyword not supported: 'provider'.

    Line 18:     protected void Button2_Click(object sender, EventArgs e)
    Line 19:     {
    Line 20:         SqlDataSource1.Insert();
    Line 21:         Response.Redirect("Default3.aspx");
    Line 22:     }

    I also tried to make a method that would store data into the database using 

    the oledb connection script, and I'm unable to since there is an error with the

    nonExecutequery script. 

    I was wondering what would cause this to happen.

    My third question is which method is better?

    Monday, August 2, 2010 11:53 AM

Answers

  • User-1199946673 posted

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

    InsertCommand='INSERT INTO Table1(Name, Business) VALUES (@TextBox1, @TextBox2)'


            ConnectionString="<%$ ConnectionStrings:trialConnectionString2 %>"> 

     

    When using the SqlDataSource with Access, you also need to provide the ProviderName Property:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    InsertCommand='INSERT INTO Table1(Name, Business) VALUES (@TextBox1, @TextBox2)'
    ProviderName="<%$ ConnectionStrings:trialConnectionString2.ProviderName %>"
    ConnectionString="<%$ ConnectionStrings:trialConnectionString2 %>"> 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 3, 2010 12:40 AM

All replies

  • User1224194097 posted

    can you post your sql datasource  markup?


    Monday, August 2, 2010 12:41 PM
  • User-800449548 posted

    Check that you have misspelled some thing or mistake in some syntax ...


    Monday, August 2, 2010 12:45 PM
  • User528730340 posted

    Hi,

    Here is my code: 

    There is one table with two textboxes as TextBox1, and TextBox2 as the id. 


    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

    InsertCommand='INSERT INTO Table1(Name, Business) VALUES (@TextBox1, @TextBox2)'


            ConnectionString="<%$ ConnectionStrings:trialConnectionString2 %>"> 


    <InsertParameters>


    <asp:ControlParameter ControlID="TextBox1" DefaultValue="" Name="TextBox1" PropertyName="Text" />


    <asp:ControlParameter ControlID="TextBox2" DefaultValue="" Name="TextBox2" PropertyName="Text" />


    </InsertParameters>


    </asp:SqlDataSource>


    ---------------------------------------------------------------------------------------------------

    And this is the content of the configuration section from the web.config file.

    <connectionStrings>

           

            <add name="trialConnectionString4" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\WebSite\App_Data\trial.mdb"

                providerName="System.Data.OleDb" />

        </connectionStrings>


    Regards,Laughing



    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    InsertCommand='INSERT INTO Table1(Name, Business) VALUES (@TextBox1, @TextBox2)'
            ConnectionString="<%$ ConnectionStrings:trialConnectionString2 %>"> 
    <InsertParameters>
    <asp:ControlParameter ControlID="TextBox1" DefaultValue="" Name="TextBox1" PropertyName="Text" />
    <asp:ControlParameter ControlID="TextBox2" DefaultValue="" Name="TextBox2" PropertyName="Text" />
    </InsertParameters>
    </asp:SqlDataSource


    Tuesday, August 3, 2010 12:01 AM
  • User-1199946673 posted

     You're showing us trialConnectionString4, however, in your sqldatasource, you're using trialConnectionString2

    Tuesday, August 3, 2010 12:33 AM
  • User-1199946673 posted

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

    InsertCommand='INSERT INTO Table1(Name, Business) VALUES (@TextBox1, @TextBox2)'


            ConnectionString="<%$ ConnectionStrings:trialConnectionString2 %>"> 

     

    When using the SqlDataSource with Access, you also need to provide the ProviderName Property:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    InsertCommand='INSERT INTO Table1(Name, Business) VALUES (@TextBox1, @TextBox2)'
    ProviderName="<%$ ConnectionStrings:trialConnectionString2.ProviderName %>"
    ConnectionString="<%$ ConnectionStrings:trialConnectionString2 %>"> 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 3, 2010 12:40 AM
  • User528730340 posted

    Thanks for the feedback, and it worked. 

    I also didn't realize the connectionStrings from other pages were interfering with 

    the form to database page in question. 

    This question was answered.  


    Thank you very much.SmileLaughing

    Tuesday, August 3, 2010 11:04 PM