2011-12-13 6 views
0

名前(文字列)をテストデータベース(sqlce)に挿入しようとしています。基本的に、ユーザーはテキストボックス(input_box)に名前を入力し、 "Insert Button"をクリックします。ボタンをクリックすると、「送信」機能が呼び出されます。テキストボックスのテキストをinsertコマンドのパラメータとして使用します。私はそれを実行している間は何のエラーもありません。しかし、テーブルのデータをチェックすると、 "null"だけが挿入されます。私はasp.netを学ぼうとしています。どんな助けもありがとう。ありがとうございました。asp.netフォームからsqlceにデータを挿入する

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"><title>Test run</title></head> 
    <script language="C#" runat = "server"> 
     void Submit(object o, EventArgs e) 
     { 
      SqlDataSource1.Insert();    
     }  
    </script> 
<body style="height: 395px"> 
    <form id="form1" runat="server"> 
    <asp:TextBox ID="Input_box" runat="server"></asp:TextBox> 
    <asp:Button ID="Insert_button" runat="server" Text=" Insert Button" OnClick = "Submit"/> 
     <asp:SqlDataSource 
      ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
      InsertCommand="INSERT INTO Incident_Table(Assignee) VALUES (@assignee)" 
      ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
      SelectCommand="SELECT Assignee FROM Incident_Table"> 
      <InsertParameters>    
       <asp:FormParameter Name="assignee" FormField ="name"/> 
      </InsertParameters> 
     </asp:SqlDataSource>  
    </form> 
</body> 
</html> 
+0

[1]:http://i.stack.imgur.com/GvK3S.png –

答えて

0

あなたはこれを交換する必要があります。

<asp:FormParameter Name="assignee" FormField ="name"/> 

で:

<asp:FormParameter Name="assignee" FormField="Input_box" /> 
+0

はあなたのダヴィデありがとう。それは私の問題を解決:)。私もdatetimeパラメータを持っていますが、パラメータとして挿入する方法がわかりません。ユーザー入力ではないので、私はFormParameterを使用するべきではないと思います。あなたはいくつかのアイデアを提供できますか?あなたの答えをありがとう。 –