创建一个函数来查找任何表的maxid [英] make a function to find maxid for any table
本文介绍了创建一个函数来查找任何表的maxid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
我想要这样的东西:
public int FindMaxId( string TableName)
{
int i = 0 ;
if (' db。' + TableName + ' 。ToList()。Count()> 0')
i = db。 TableName.Max(d = > d.id);
return i;
}
我知道这是错的。我想传递表名,然后返回最大ID。对于任何一个表。
解决方案
你好...
这段代码可以帮助你
Public GetMaxid()
{
con.Open();
OleDbCommand cmd1 = new OleDbCommand( 选择Max(ProductGroupCode)作为ProductGroup_master,con)的maxid;
OleDbDataReader oledbrd1 = cmd1.ExecuteReader();
oledbrd1.Read();
if (Convert.IsDBNull(oledbrd1 [ maxid])) // 检查db是否为NULL
{
strid1 = 1 ;
txt_pgrpcode.Text = 1;
}
else
{
strid1 = Convert.ToInt32(oledbrd1 [ maxid])+ 1 ;
txt_pgrpcode.Text = strid1.ToString();
}
oledbrd1.Close();
}
Hpaay Coding :) :)
hi
I would like something like this:
public int FindMaxId(string TableName)
{
int i =0;
if ('db.'+TableName+'.ToList().Count() > 0' )
i = db. TableName.Max(d => d.id);
return i ;
}
i know it's wrong .i wanna pass the name of table , and it returns max id. for any table.
解决方案
Hi...
this code may help you
Public GetMaxid() { con.Open(); OleDbCommand cmd1 = new OleDbCommand("Select Max(ProductGroupCode) as maxid from ProductGroup_master", con); OleDbDataReader oledbrd1 = cmd1.ExecuteReader(); oledbrd1.Read(); if (Convert.IsDBNull(oledbrd1["maxid"]))//check if db is NULL { strid1 = 1; txt_pgrpcode.Text = "1"; } else { strid1 = Convert.ToInt32(oledbrd1["maxid"]) + 1; txt_pgrpcode.Text = strid1.ToString(); } oledbrd1.Close(); }
Hpaay Coding :) :)
这篇关于创建一个函数来查找任何表的maxid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文