类的参数使用 [英] Class use of the parameter
本文介绍了类的参数使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我想现在学习这一点,当普通代码直接采用连接到sql类端的参数值时,但是我不知道该怎么办.为了提供下面提到的代码的这一部分的示例,您需要使用类来处理这些参数.我如何披露自己的示例,对此感到非常满意.在此先感谢您,祝您度过愉快的一天.
Hello, I want to learn this now, when the normal code directly taking on the value of parameters mentioned connecting to sql class side, but I do not know how you can do. To give an example of this part of the code mentioned below, there are the parameters you need to do with class How do I disclose my examples were very pleased with the stay. Thanks in advance have a nice day.
SqlConnection cnn = new SqlConnection("ConnectionString");
cnn.Open();
SqlCommand cmd = new SqlCommand("Insert into Products(UrunID,CategoryID) values(@id,@katid)",cnn);
cmd.Parameters.AddWithValue("@id", value.Text);
cmd.Parameters.AddWithValue("@katid",value.Text);
cmd.ExecuteNonQuery();
cnn.Close();
推荐答案
我不确定这是否是您想要的
Im not sure if this is what you want
#region
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
#endregion
namespace ConsoleApplication1
{
internal class Program
{
private static void Main(string[] args)
{
loadinfo(args[0], args[1]);
}
private static void loadinfo(string x, string y)
{
var cnn = new SqlConnection("ConnectionString");
cnn.Open();
var cmd = new SqlCommand("Insert into Products(UrunID,CategoryID) values(@id,@katid)", cnn);
cmd.Parameters.AddWithValue("@id", x);
cmd.Parameters.AddWithValue("@katid", y);
cmd.ExecuteNonQuery();
cnn.Close();
}
}
}
您要问的只是 ^ ],您可以在创建类的实例时传递它..
请参阅相同的文章:
C#构造函数和.NET 4.0可选参数 [ ^ ]
C#中的构造函数参数验证-最佳做法 [ ^ ]
您还应该了解 C#4.0命名用于提高代码质量的参数 [
The thing which you are asking is nothing but Constructor With Parameters[^], which you can pass while creating the instance of the class..
Refer the articles for the same:
C# Constructors and .NET 4.0 Optional Parameters[^]
Constructor parameter validation in C# - Best practices[^]
You should also know about C# 4.0 Named Parameters for better code quality[^]
-Amit
这篇关于类的参数使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文