将字符串传递给另一个类 [英] Pass Strings to another class

查看:68
本文介绍了将字符串传递给另一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我遇到了一个小问题,我正在尝试将字符串传递给项目中的另一个类。基本上,我已经形成了2个字符串(通过DAL类插入数据库),所以我在发送字符串时遇到了麻烦。任何帮助都感激不尽。代码如下:



Hi All ,

I am experiencing a small problem, I am trying to pass/send strings to another class within a project. Basically , I have formed 2 strings (to be inserted into a Database via a DAL class), so I am having trouble sending the strings across. Any help will be much appreciated. Code below :

  namespace SendFile
{
    public class File: IFile
    { 


     public string Insert(string InsertDLog, string InstrValue) //this method takes in 2 parameters , from here i need to send the strings to the DAL.cs
        {

            string InsertXMl = Insert.ToString();
            string Id = InstrValue.ToString();

            return null;
        }
}
}







namespace SendFile
{
    public static class DAL
    {

        public static void InsertDB()
        {
            
            string connection = ConfigurationManager.ConnectionStrings["DConnection"].ConnectionString;
            string StoredProc = ConfigurationManager.AppSettings["Insert_Update"];
            
            try
            {
                SqlConnection conn = new SqlConnection(connection);
                SqlCommand cmd = new SqlCommand(StoredProc,conn);

                cmd.CommandType = CommandType.StoredProcedure;


                cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = null; // This value needs to be the ID from the Insert method (SendFile)
                cmd.Parameters.Add("@StatusID", SqlDbType.Int).Value = 1;
                cmd.Parameters.Add("@Message", SqlDbType.Xml).Value = null;// This value needs to be the InsertXMl from the Insert method (SendFile)

                conn.Open();
                cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                throw ex;
            }
}
}





谢谢



Thanks

推荐答案

namespace SendFile
{
    public class File: IFile
    {


     public string Insert(string InsertDLog, string InstrValue) //this method takes in 2 parameters , from here i need to send the strings to the DAL.cs
        {

            string InsertXMl = Insert.ToString();
            string Id = InstrValue.ToString();
DAL.InsertDB(Id,InsertXMl );


            return null;
        }
}
}






















namespace SendFile
{
    public static class DAL
    {
 
        public static void InsertDB(string Id , string InsertXMl )
        {
            
            string connection = ConfigurationManager.ConnectionStrings["DConnection"].ConnectionString;
            string StoredProc = ConfigurationManager.AppSettings["Insert_Update"];
            
            try
            {
                SqlConnection conn = new SqlConnection(connection);
                SqlCommand cmd = new SqlCommand(StoredProc,conn);
 
                cmd.CommandType = CommandType.StoredProcedure;
 

                cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = Id ; // This value needs to be the ID from the Insert method (SendFile)
                cmd.Parameters.Add("@StatusID", SqlDbType.Int).Value = 1;
                cmd.Parameters.Add("@Message", SqlDbType.Xml).Value = InsertXMl ;// This value needs to be the InsertXMl from the Insert method (SendFile)

                conn.Open();
                cmd.ExecuteNonQuery();
 
            }
            catch (Exception ex)
            {
                throw ex;
            }
}
}


这篇关于将字符串传递给另一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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