自动生成字母数字代码字符串sql server c#asp .net [英] autogenerate alphanumeric code string sql server c # asp .net

查看:47
本文介绍了自动生成字母数字代码字符串sql server c#asp .net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


早上好


我需要你的帮助我正在创建一个应用程序,它应该生成一个自动代码字母数字

我已经提出了这个查询,但是我把它放了错误我需要帮助我最好的方法来做到这一点并且能够理想地拥有它是字母数字NCL然后连续数字我保留两个表一个叫做客户显示代码而另一个叫Gcodigo就是
一个那将有我离开代码的操作来帮助我,并且有一种方法可以使用存储过程来实现它会更好我是初学者就是这个,这是我的大学项目。


使用System;

使用System.Collections.Generic;

使用System< g class =" gr_ gr_55 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep"数据-GR-ID =" 55" id =" 55" .Linq< / g> ;;

using system< g class =" gr_ gr_56 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep"数据-GR-ID =" 56" id =" 56"> .Text< / g> ;;

使用System.Threading.Tasks;



使用System.Data ;
$
使用System.Data.SqlClient;
$


命名空间CapaLogicaNegocio.BL

{

  &NBSP;公共课clsGCodigoCliente

  &NBSP; {

  &NBSP; &NBSP; &NBSP; SqlConnection _SqlConnection = null; //我是permite establecer comunicacion con bbdd

  &NBSP; &NBSP; &NBSP; SqlCommand _sqlCommand = null; // me permite ejecutar comandos SQL

  &NBSP; &NBSP; &NBSP; SqlDataAdapter _sqlDataAdapter = null; //我permite adaptar conjuntod de datos SQL

  &NBSP; &NBSP; &NBSP; string stConexion = string.Empty; // cadena de conexion 



  &NBSP; &NBSP; &NBSP; SqlParameter sqlParameter = null;



  &NBSP; &NBSP; &NBSP; public clsGCodigoCliente()

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ClsConexion obclsConexion = new ClsConexion();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; stConexion = obclsConexion.getConexion();

  &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; // VALIDAR USUARIO

  &NBSP; &NBSP; &NBSP; public string GeneradorCodigo(string nomtabla)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SqlConnection cn = instacia.CadenaConexion();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string resultado ="" ;;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; int ceros = 0;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string Codigo ="" ;;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DataSet ds = new DataSet();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SqlDataAdapter consulta = new SqlDataAdapter("选择来自GCodigoCliente的NUMERO,其中NombTabla ='" + nomtabla +"'",cn);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ds.Reset();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; consulta.Fill(ds,"GCodigoCliente");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(ds.Tables [" GCodigoCliente"]。Rows.Count> 0)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; resultado = ds.Tables [" GCodigoCliente"]。行[0] [0] + 1.ToString()。修剪();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ceros = 4 - resultado.Length;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;开关(ceros)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例0:

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Codigo ="NCL0000" + resultado;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例1:

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Codigo ="NCL000" + resultado;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例2:

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Codigo ="NCL00" + resultado;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例3:

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Codigo ="NCL0" + resultado;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;否则

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回Codigo;

  &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; }
}


< o:p>< / o:p>

解决方案

朋友,


感谢您在此发帖。


此论坛是关于Visual Studio中的测试。


由于你的问题与asp.net开发有关,我建议你可以在
stackoverflow Asp.net论坛。该论坛上的更多社区成员可能会进一步查看您的问题并提供更多建议。


如果您对Visual Studio中的测试有疑问,请随时与我们联系。我们将尽力为您提供解决方案。

感谢您的理解与合作。 


最好的问候


兰斯


Good morning

I need your help I'm creating an application which should generate an automatic code alphanumeric
I have made this query, but I put error I need to help me the best way to do it and be able to have it ideally is alphanumeric NCL and then the consecutive number I keep two tables one called customer which show the code and another call Gcodigo which is the one that will have the operation I leave the code to help me and there is a way to do it with a stored procedure would be better I am a beginner is this and it is my project of the university.

using System;
using System.Collections.Generic;
using System<g class="gr_ gr_55 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="55" id="55">.Linq</g>;
using System<g class="gr_ gr_56 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="56" id="56">.Text</g>;
using System.Threading.Tasks;

using System.Data;
using System.Data.SqlClient;

namespace CapaLogicaNegocio.BL
{
    public class clsGCodigoCliente
    {
        SqlConnection _SqlConnection = null;//me permite establecer comunicacion con bbdd
        SqlCommand _sqlCommand = null; // me permite ejecutar comandos SQL
        SqlDataAdapter _sqlDataAdapter = null; //me permite adaptar conjuntod de datos SQL
        string stConexion = string.Empty;//cadena de conexion 

        SqlParameter sqlParameter = null;

        public clsGCodigoCliente()
        {
            ClsConexion obclsConexion = new ClsConexion();
            stConexion = obclsConexion.getConexion();
        }

        //VALIDAR USUARIO
        public string GeneradorCodigo(string nomtabla)
        {
            SqlConnection cn = instacia.CadenaConexion();
            string resultado = "";
            int ceros = 0;
            string Codigo = "";
            DataSet ds = new DataSet();
            SqlDataAdapter consulta = new SqlDataAdapter("select NUMERO from GCodigoCliente where NombTabla='" + nomtabla + "'", cn);
            ds.Reset();
            consulta.Fill(ds, "GCodigoCliente");
            if(ds.Tables["GCodigoCliente"].Rows.Count > 0)
            {
                resultado = ds.Tables["GCodigoCliente"].Rows[0][0] + 1.ToString().Trim();
                ceros = 4 - resultado.Length;
                switch (ceros)
                {
                    case 0:
                        Codigo = "NCL0000" + resultado;
                        break;
                    case 1:
                        Codigo = "NCL000" + resultado;
                        break;
                    case 2:
                        Codigo = "NCL00" + resultado;
                        break;
                    case 3:
                        Codigo = "NCL0" + resultado;
                        break;
                }
            }
            else
            {

            }
            return Codigo;
        }
    }
}

<o:p></o:p>

解决方案

Hi friend,

Thanks for posting here.

This forum is about Tests in visual studio.

As your issue is more related to the asp.net development, I suggest that you could open an new thread on the stackoverflow or Asp.net forum with Asp.net tag. More community members on that forum may further look at your issue and provide more suggestions.

And if you have some questions about tests in Visual Studio, please feel free to contact us. We will try our best to give you a solution.
Thanks for your understanding and cooperation. 

Best Regards

Lance


这篇关于自动生成字母数字代码字符串sql server c#asp .net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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