本文介绍了SQLHelper.cs和C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个称为:
的存储过程带有参数的Terminal_Vendor:用户名,密码,terminalSerial,日期.
所以我该如何在sqlhelper中添加它并在login.aspx.cs/
中调用它
在此先感谢

Im having a store procedure called :
Terminal_Vendor with the param: username,pwd,terminalSerial,date.
so how can i add it in sqlhelper and call it in login.aspx.cs/

Thanks in advance

推荐答案

try to analyze this code and modify
hope this can help you


public static User GetOneUserBy(string username, string password, string Tserial, DateTime tdate )
        {
            try
            {
                string strCommandText = "GetOneUser";
                User dto;
                using (SqlConnection cn = new SqlConnection(SQLHelper.GetConnectionString()))
                {
                    SqlCommand cmd = new SqlCommand(strCommandText, cn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    
                    SqlParameter paramUsername = new SqlParameter("@Username", System.Data.SqlDbType.NVarChar, 50);
                    paramUsername.Value = username;
                    cmd.Parameters.Add(paramUsername);
                    SqlParameter paramPwd = new SqlParameter("@Password", System.Data.SqlDbType.NVarChar, 50);
                    paramPwd.Value = username;
                    cmd.Parameters.Add(paramPwd);
                    SqlParameter paramTerminalSerial = new SqlParameter("@TerminalSerial", System.Data.SqlDbType.NVarChar, 50);
                    paramPwd.Value = Tserial;
                    cmd.Parameters.Add(paramTerminalSerial);
                    SqlParameter paramTDate = new SqlParameter("@tDate", System.Data.SqlDbType.DateTime);
                    paramPwd.Value = tdate;
                    cmd.Parameters.Add(paramTDate);

                    SqlDataReader reader = null;
                    dto = new User();
                    cn.Open();
                    reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            dto.Name = (reader.IsDBNull(reader.GetOrdinal("Name"))) ? null : (System.String)reader["Name"];
                            dto.Address = (reader.IsDBNull(reader.GetOrdinal("Address"))) ? null : (System.String)reader["Address"];
                            dto.PhoneNo = (reader.IsDBNull(reader.GetOrdinal("PhoneNo"))) ? null : (System.String)reader["PhoneNo"];
                            dto.UserName = (reader.IsDBNull(reader.GetOrdinal("UserName"))) ? null : (System.String)reader["UserName"];
                            dto.Password = (reader.IsDBNull(reader.GetOrdinal("Password"))) ? null : (System.String)reader["Password"];
                            dto.Email = (reader.IsDBNull(reader.GetOrdinal("Email"))) ? null : (System.String)reader["Email"];
                        }
                    }
                }
                return dto;
            }
            catch (Exception ex)
            {
                throw;
            }
        }



谢谢



Thanks


这篇关于SQLHelper.cs和C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 04:49