如何使用where条件向sql插入值? [英] how to insert values to sql using where condition?

查看:118
本文介绍了如何使用where条件向sql插入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Button4_Click(object sender, EventArgs e)
   {

       SqlConnection conn2 = new SqlConnection();
       conn2.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=travel_Directions;Integrated Security=True";
       conn2.Open();

       String selQuery = "SELECT (Source,Destination) FROM MapDataImage WHERE Source='" + TextBox1.Text + "' and Destination='" + TextBox2.Text + "' ;";
           {

       string querysql = "INSERT INTO MapDataImage(User_Comment) VALUES (@User_Comment) S




       //scmd.Parameters.AddWithValue("@User_Comment", Commentary.Value);


       scmd.Parameters.Add("@User_Comment", Commentary.Value);
       scmd.ExecuteNonQuery();



       conn2.Close();

   }





是这个问题还是错了?

以及我将如何做到这一点?



i想先检查源和目的地

然后我想添加评论到User_CommentField



is this corrct or wrong ?
and how i'm gonna do that?

i want check source and destination first
and then i want to add comment to User_CommentField

推荐答案

首先,阅读Chill60的评论......



如果你想检查是否值存在,请使用存储过程 [ ^ 代替做代码背后。



如何:致电使用ADO.NET和Visual C#.NET进行参数化存储过程 [ ^ ]

使用存储过程修改数据 [ ^ ]

在ADO.NET中调用存储过程 [ ^ ]
First of all, read Chill60's comment...

If you want to check if value exists, please, use stored procedures[^] instead doing it in code behind.

HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET[^]
Modifying Data with Stored Procedures[^]
Calling Stored procedures in ADO.NET[^]


这篇关于如何使用where条件向sql插入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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