如何编辑Sql Ce Edition数据库? [英] How Do I Edit Sql Ce Edition Database?

查看:82
本文介绍了如何编辑Sql Ce Edition数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个紧凑版的sql server连接



它完美运行...

但我无法手动编辑表格



  string  item = itemName.Text; 
int 数量= Convert.ToInt32(itemQty.Text);


string connectionString = 数据源= C:\\Users \\Jeewani \\Documents\\rundown.sdf;;

SqlCeConnection sql = new SqlCeConnection(connectionString);

sql.Open();

string query = INSERT INTO ItemsNames(ItemName,ItemQty)VALUES(' + item + ',' + Qty + ');



SqlCeCommand myCommand = new SqlCeCommand(query,sql);

myCommand.ExecuteNonQuery();

// myinfo.Text =与db建立连接;
sql.Close();





谢谢

解决方案

< blockquote>试试这个项目: https://sqlcedatabaseeditor.codeplex.com/ [ ^ ]


我想我遇到了这个问题...



A 数量变量是整数数据类型:

  int  Qty = Convert.ToInt32(itemQty.Text); 





所以,你需要更换这个:

  string  query =   INSERT INTO ItemsNames(ItemName,ItemQty)VALUES(' + item +  ',' +数量+  '); 



这个:

  string  query =   INSERT INTO ItemsNames(ItemName,ItemQty)VALUES(' + item + < span class =code-string> ', + Qty +  < span class =code-string>); 





有什么区别?我在数量附近删除了''



注意:您的代码是 sql注入 [ ^ ]可用。解决方案:使用参数化查询 [ ^ ]。


i have created a compact edition sql server connection

it works perfectly...
but i cant edit table manually

string item = itemName.Text;
            int Qty = Convert.ToInt32(itemQty.Text);


            string connectionString = "Data Source=C:\\Users\\Jeewani\\Documents\\rundown.sdf;";

            SqlCeConnection sql = new SqlCeConnection(connectionString);

            sql.Open();

            string query = "INSERT INTO ItemsNames(ItemName,ItemQty) VALUES('" + item + "', '" + Qty + "')";

            

            SqlCeCommand myCommand = new SqlCeCommand(query, sql);

            myCommand.ExecuteNonQuery();

            //       myinfo.Text = "connection to db is made";
            sql.Close();



thank you

解决方案

Try this project : https://sqlcedatabaseeditor.codeplex.com/[^]


I think i got the issue...

A Qty variable is integer data type:

int Qty = Convert.ToInt32(itemQty.Text);



So, you need to replace this:

string query = "INSERT INTO ItemsNames(ItemName,ItemQty) VALUES('" + item + "', '" + Qty + "')";


with this:

string query = "INSERT INTO ItemsNames(ItemName,ItemQty) VALUES('" + item + "', " + Qty + ")";



What's the difference? I removed '' around Qty.

Note: your code is sql injection[^] volnurable. Solution: Use parametrized queries[^].


这篇关于如何编辑Sql Ce Edition数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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