开发者

mysql odbc not saving contents of table?

I have a client control which takes a textbox a button and applys what ever is written to my html on my asp page using jquery/javascript.

<script type="text/javascript">
    $(function () {

        $('[name*= "Button1"]').click(function () {
            var x = $('[name*= "TextBox1"]').val();
            var newdiv = $("<div></div>").html(x).attr('id', 'test');

            $('#test1').append(newdiv);
            $('[name*= "Table1"]').text($('#test1').html());
            $('[name*= "TextBox1"]').val('');

            return false;

        });
    });  
</script>
<p>
    <asp:TextBox ID="TextBox1" name="TextBox1" runat="server" Rows="3" 
        Height="47px" Width="638px"></asp:TextBox>
</p>
<p>
    <asp:Button ID="Button1" runat="server" Text="Post Message" Width="98px" 
        onclick="Button1_Click" /></p>
<p>
    <asp:Table ID="Table1" name="Table1" runat="server" Width="488px"></asp:Table>
</p>

<div id="test1"></div>

</asp:Content>

When it does this I also output the contents to a table(unformatted) so in the table I get things that look like this <div id="test">wsefwefwef</div><div id="test">wefwefwef</div> <- random buttons I pressed in the textbox and clicked my button. This all works fine.

But when I try to save the contents of my Tabel1 to mysql using odbc nothing is saved?

    {
        string theUserId开发者_运维百科 = Session["UserID"].ToString();
        OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite; User=x; Password=x;");
        cn.Open();

        OdbcCommand cmd = new OdbcCommand("INSERT INTO WallPostings (UserID, Wallpostings) VALUES ('UserID="+theUserId+"','"+Table1+"')", cn);
        cmd.ExecuteNonQuery();


    }
}

can anyone help ammend my connection/sql syntax c# as no data is being inserted?


You are calling ExecuteReader when you should probably be calling ExecuteNonQuery.


You should you Table1.InnerHTML or Text as Value. And use ExecuteNonQuery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜