在C#和SQL Server CE 4.0中存储额外部分的数据 [英] Store data with extra part in C# and SQL Server CE 4.0

查看:68
本文介绍了在C#和SQL Server CE 4.0中存储额外部分的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#和MicrosoftMicrosoft®SQLServer®Compact



所有数据在数据库中插入这样的数据



Ex我这样输入我的名字数据库商店



System.Windows.Forms.TextBox,Text:chamikara



有什么方法可以删除这部分系统.Windows.Forms。文本框,文字:



非常感谢您的帮助





我的代码



I'm using C# and Microsoft Microsoft® SQL Server® Compact

All data inserts like this in the database

Ex I input my name database store like this

System.Windows.Forms.TextBox, Text: chamikara

There any way to remove this part "System. Windows. Forms. TextBox, Text: "

your help is greatly appreciated


My Code

SqlCeConnection con = new SqlCeConnection("Data Source=" + app_path + "\\application.sdf;Persist Security Info=False;");
            con.Open();
            SqlCeCommand cm = new SqlCeCommand("INSERT INTO tbl_user(u_id,u_name,u_scl,u_que) VALUES (@u_id,@u_name, @u_scl, @u_que)", con);
            cm.Parameters.AddWithValue("@u_id", 1);
            cm.Parameters.AddWithValue("@u_name", txtpass.ToString());
            cm.Parameters.AddWithValue("@u_scl", txtans.ToString());
            cm.Parameters.AddWithValue("@u_que", index);      
            

            try
            {
                int eff = cm.ExecuteNonQuery();

                if (eff == 1)
                {
                    con.Close();
                    MessageBox.Show("Data Added " , "Done");
                }
                else
                {
                    con.Close();
                    MessageBox.Show("not inserted ", "Error");
                }
            }
            catch (SqlCeException ex)
            {
                MessageBox.Show(ex.ToString());
            }

推荐答案

是的。要么:

1)使用TextBox.Text属性而不是Textbox.ToString方法。

2)使用参数化查询和TextBox.Text属性。这样你也可以避免SQL注入攻击,这可能会破坏或破坏你的数据库......
Yes. Either:
1) Use the TextBox.Text property instead of the Textbox.ToString method.
2) Use parametrised queries and the TextBox.Text property. This way you avoid SQL Injection attacks as well, which can damage or destroy your database...


这篇关于在C#和SQL Server CE 4.0中存储额外部分的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆