|
|
|
อยากรบกวน ถาม โค๊ด generate number แบบรันไปเรื่อยๆอะคะ |
|
|
|
|
|
|
|
Code (C#)
public string GetId(string pname)
{
Conn = new SqlConnection();
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
}
Conn.ConnectionString = DBConnString.strConn;
Conn.Open();
string pid;
string strSql = "SELECT max(right(packing_no,7))+1 as id FROM PICKING" ;
int x;
com = new SqlCommand();
com.CommandType = CommandType.Text;
com.CommandText = strSql;
com.Connection = Conn;
dr = com.ExecuteReader();
DataTable dt = new DataTable();
if (dr.HasRows)
{
dt.Load(dr);
}
dr.Close();
Conn.Close();
try
{
x = Convert.ToInt32(dt.Rows[0]["id"]);
}
catch
{
x = 1;
}
pid = x.ToString("0000000");
pid = pname + pid;
return pid;
}
เรียกใช้
Code (C#)
txtBox_GenPickNO.text= GetId("P10");
|
|
|
|
|
Date :
2010-03-17 16:47:36 |
By :
msorawich |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คือ มันติดต่อฐานข้อมูลไม่ได้อะคะ งง ^^"
หรือเราต้อง แก้ หรือ ลบ ตรงไหน มั๊ยค่ะ
รบกวนอีกทีนะคะ ...วิกฤต จิง T-T
protected void enterPick_Click(object sender, EventArgs e)
{
txtBox_GenPickNO.text = GetId("P10");
}
public string GetId(string pname)
{
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
IDbConnection con = factory.CreateConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["dbInvoice"].ToString();
IDbCommand com = factory.CreateCommand();
com.Connection = con;
con.Open();
con = new SqlConnection();
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
}
Conn.ConnectionString = DBConnString.strConn;
Conn.Open();
string pid;
string strSql = "SELECT max(right(packing_no,7))+1 as id FROM PICKING" ;
int x;
com = new SqlCommand();
com.CommandType = CommandType.Text;
com.CommandText = strSql;
com.Connection = Conn;
dr = com.ExecuteReader();
DataTable dt = new DataTable();
if (dr.HasRows)
{
dt.Load(dr);
}
dr.Close();
Conn.Close();
try
{
x = Convert.ToInt32(dt.Rows[0]["id"]);
}
catch
{
x = 1;
}
pid = x.ToString("0000000");
pid = pname + pid;
return pid;
}
|
|
|
|
|
Date :
2010-03-17 17:10:32 |
By :
มูมู่ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
public string GetId(string pname)
{
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
IDbConnection con = factory.CreateConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["dbInvoice"].ToString();
IDbCommand com = factory.CreateCommand();
com.Connection = con;
con.Open();
string pid;
string strSql = "SELECT max(right(packing_no,7))+1 as id FROM PICKING" ;
int x;
com = new SqlCommand();
com.CommandType = CommandType.Text;
com.CommandText = strSql;
com.Connection = con;
dr = com.ExecuteReader();
DataTable dt = new DataTable();
if (dr.HasRows)
{
dt.Load(dr);
}
dr.Close();
con.Close();
try
{
x = Convert.ToInt32(dt.Rows[0]["id"]);
}
catch
{
x = 1;
}
pid = x.ToString("0000000");
pid = pname + pid;
return pid;
}
|
|
|
|
|
Date :
2010-03-17 17:25:14 |
By :
msorawich |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แฮะๆ รบกวนอีกที คะ พี่
protected void enterPick_Click(object sender, EventArgs e)
{
txtBox_GenPickNO.Text = GetId("P10");
}
public string GetId(string pname)
{
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
IDbConnection con = factory.CreateConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["dbInvoice"].ToString();
IDbCommand com = factory.CreateCommand();
com.Connection = con;
con.Open();
string pid;
string strSql = "SELECT max(right(packing_no,7))+1 as id FROM PICKING";
int x;
com = new SqlCommand();
com.CommandType = CommandType.Text;
com.CommandText = strSql;
com.Connection = con;
dr = com.ExecuteReader();
DataTable dt = new DataTable();
if (dr.HasRows)
{
dt.Load(dr);
}
dr.Close();
con.Close();
try
{
x = Convert.ToInt32(dt.Rows[0]["id"]);
}
catch
{
x = 1;
}
pid = x.ToString("0000000");
pid = pname + pid;
return pid;
}
มันรัน มะผ่านอะคะ ตรง ที่ ขีดเส้นใต้
ละก้อ ตัวแปร dt dr มานมะ รู้ จัก อะคะ ^^" รบกวนอีกทีน่ะคะ พี่ msorawich
ขอบคุณล่วงหน้าค่ะ
|
|
|
|
|
Date :
2010-03-17 17:47:56 |
By :
มูมู่ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แง่วๆๆ T-T
|
|
|
|
|
Date :
2010-03-18 01:45:17 |
By :
มูมู่ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|