如何给ADO.NET参数 [英] How to give ADO.NET Parameters

查看:70
本文介绍了如何给ADO.NET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个将记录添加到DB的SQL命令。我尝试了以下代码,但它似乎不起作用:

I want to create a SQL command that adds record to DB. I tried the following code but it doesn't seem to be working:

SqlCommand comand = new SqlCommand("INSERT INTO Product_table Values(@Product_Name,@Product_Price,@Product_Profit,@p)", connect);
SqlParameter ppar = new SqlParameter();
ppar.ParameterName = "@Product_Name";
ppar.Value = textBox1.Text;
MessageBox.Show("Done");
comaand.Parameters.Add(ppar);


推荐答案

在您的情况下,您似乎在使用。净。使用参数非常简单:

In your case, it looks like you're using .NET. Using parameters is as easy as:

C#

 string sql = "SELECT empSalary from employee where salary = @salary";
 SqlConnection connection = new SqlConnection(/* connection info */);
 SqlCommand command = new SqlCommand(sql, connection);

 command.Parameters.AddWithValue("salary", txtSalary.Text);

这篇关于如何给ADO.NET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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