来自文本字段的SQL更新记录 [英] SQL Update record from textfields

查看:96
本文介绍了来自文本字段的SQL更新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修改此代码以更新数据库中的记录?

How should I modify this code to Update my record in the database?

private void KlantenInfoUploaden()
        {
            string Organisatie = TX_Organisatie.Text;
            string BezoekAdres = TX_BezoekAdres.Text;
            String BezoekPostCode = TX_BezoekPostCode.Text;
            string BezoekPlaats = TX_BezoekPlaats.Text;

            string FactuurAdres = TX_FactuurAdres.Text;
            string FactuurPostCode = TX_FactuurPostCode.Text;
            string FactuurPlaats = TX_FactuurPlaats.Text;

            string Telefoon = TX_Telefoon.Text;
            string Fax = TX_Fax.Text;
            string Email = TX_Email.Text;
            string Website = TX_Website.Text;

            const string queryKLantBewerkenID = "Update Organisatie, bezoek_adres, bezoek_postcode, bezoek_plaats, factuur_adres, factuur_postcode, factuur_plaats, telefoon, fax, mail, website FROM Klanten WHERE [IDklanten] = @KlantID";

            using (SqlConnection connection = new SqlConnection(connectionstring))
            using (SqlCommand command = new SqlCommand(queryKLantBewerkenID, connection))
            { 
                command.Parameters.AddWithValue("@KlantID", XX_klantID.Text);

                try {
                    connection.Open();
                    
              //HELP!


                }
                catch(Exception exp) {
                    MessageBox.Show("FOUT");
                }
                
            }
        }

推荐答案

您的SQL命令无效:如果我把大部分内容都删掉了,那么它的可读性就更高了:

Your SQL command is not valid: If I rip out most of it so it;s more readable then it comes down to:
Update Organisatie FROM Klanten WHERE [IDklanten] = @KlantID

SELECT命令的格式不是更新。

您需要:

Which is the format for a SELECT command not an update.
You need:

UPDATE Klanten SET Organisatie=@ORG WHERE [IDklanten] = @KlantID

并通过参数以与@KlantID相同的方式提供@ORG值。

然后一个command.ExecuteNonQuery将进行更新。

And to supply the "@ORG" value via a parameter in the same way you do @KlantID.
Then a command.ExecuteNonQuery will do the update.


command.ExecuteNonQuery();



似乎是一个合理的选择。


seems a reasonable choice.


这篇关于来自文本字段的SQL更新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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