更新数据库上的查询字符串 [英] Updating a query string on database

查看:60
本文介绍了更新数据库上的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我记录了一个场景,在我的查询字符串中,一旦我收到它,我将它保存在数据库上。然后我继续在我需要的字符串中提取那些参数。我在某种程度上卡住了更新查询字符串。在数据库中,它添加了一个查询字符串的两条记录。一个用于整个查询字符串,另一个用于提取的字段项。这是我可以阻止这个双重条目的方式,因为整个数据库有很多记录混淆了null值。我只需要更新我在数据库中首先添加的查询字符串。谢谢



下面是我的代码



Hi all,i jave a scenario whereby in my query string ,i save it on the databse once i have received it.After that then i go on exttracting those parameters in the string i need.Where i am somehow stuck is updating that query string.On the database it adds two records of one query string .,One for the whole query string and other one for the extracted field items.I s their a way i can prevent this double entry since the whole db has many records mixed up with null values.I need only to update that query string i added first in the database.Thanks

Below is my code

string queryStringData = newString;
               StudentManagement.AddString(queryStringData );





                if (string.IsNullOrEmpty(newString))
                {
                  
                    return;

                }
                else
                {

                    StudentId = int.Parse(context.Request.QueryString["id"].ToString());
                    AdmissionNumber= context.Request.QueryString["AdmNo"];
StudentManagement.AddStudents(StudentId ,AdmissionNumber);







我添加学生的方法




My method to add students

public void AddStudents(StudentId ,AdmissionNumber)
{
Students addStudents=new Students;
StudentId ==StudentId ,
AdmissionNumber==AdmissionNumber
               
 db.Students.InsertOnSubmit(addStudents);

db.SubmitChanges(ConflictMode.FailOnFirstConflict)
}





添加学生方法是一个更新保存在数据库上的查询字符串,有人可以指导吗?谢谢



The add Students method is the one to update the query string saved on the database,Can someone guide on this?Thanks

推荐答案

1。为数据库设置约束以防止双重输入。

2.在我看来,SubmitChanges认为记录是新记录。 (你也可以学生addStudents =新学生; 所以它实际上是一个新纪录) - >我在这里假设您省略了一些代码行?您应该从db对象中获取EXISTING值(或者绑定到此对象的任何对象),更改值然后调用SubmitChanges。

3.如果您告诉我们什么是数据库会有所帮助你正在努力。

4.你在使用LINQ吗?在这种情况下,SubmitChanges将生成一个SQL,您可以在Visual Studio的输出窗口中看到该SQL。如果您正在插入或更新,它会立即告诉您。



如果您使用更多代码更新问题,可能会更好。



希望这会有所帮助。
1. Set constraints to your database to prevent double entries.
2. It looks to me like the SubmitChanges thinks the records is a new one. (You also do Students addStudents=new Students; so it is in fact a new record) --> I assume here that you omitted some lines of code? You should get out the EXISTING value from the db object (or whatever object is bound to this), change the values and then call SubmitChanges.
3. It would help if you would let us know what database you're working on.
4. Are you working with LINQ? in that case the SubmitChanges will generate an SQL which you can see in the output window of Visual Studio. That will immediately tell you if you're inserting or updating.

It's probably better if you update your question with a little more code.

Hope this helps.


这篇关于更新数据库上的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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