怎么写这段代码? [英] how to write this code?

查看:65
本文介绍了怎么写这段代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为我创建的一个名为newmembers的表单编写代码,该表单采用string,int,string但我不知道如何在app_code中为它编写类



  public   class  newmember 
{
public static string 注册(< span class =code-keyword> string mname, int 密码,字符串电子邮件)
{
SqlConnection con = new SqlConnection(Database.ConnectionString);
尝试







}





也许我应该补充说,该方法的功能是获取这些值并将它们添加到数据库中的一个表中使用

span>(SqlConnection con = new SqlConnection(Database.ConnectionString))
{
con.Open();
使用(SqlCommand com = new SqlCommand( INSERT INTO myTable(myColumn1,myColumn2,myColumn3)VALUES(@NM,@ PW,@ EM),con))
{
com.Parameters.AddWithValue( @ NM,mname);
com.Parameters.AddWithValue( @ PW,密码);
com.Parameters.AddWithValue( @ EM,email);
com.ExecuteNonQuery();
}
}

显然,您需要适当的表名和列名! :笑:

I need to write a code for a form I created called newmembers that takes string,int,string but i did not know how to write the class for it in the app_code

public class newmember
 {
     public static string Register(string mname, int password, string email)
     {
         SqlConnection con = new SqlConnection(Database.ConnectionString);
         try







 }



maybe i should add that the function of the method is to take these values and add them to a table in the database called members.

解决方案

Try:

using (SqlConnection con = new SqlConnection(Database.ConnectionString))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2, myColumn3) VALUES (@NM, @PW, @EM)", con))
        {
        com.Parameters.AddWithValue("@NM", mname);
        com.Parameters.AddWithValue("@PW", password);
        com.Parameters.AddWithValue("@EM", email);
        com.ExecuteNonQuery();
        }
    }

Obviously, you need to your the appropriate table and column names! :laugh:


这篇关于怎么写这段代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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