建立数据库含表t1,主键为自动编号的id
现想取得id值后的到+1后的值(如果得到id=8,想把9赋予string型的t;得到id=12,赋t=13)
请问语句如何实现?
id 的类型是int 还是string的?

解决方案 »

  1.   

    int型
    不可能是string型的,除非你自己加再存进去,哈哈。
      

  2.   

    主要这句
    select id,'t'=id+1 from t1
    string mySelectQuery = "select id,'t'=id+1 from t1";
        SqlConnection myConnection = new SqlConnection(myConnString);
        SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
        myConnection.Open();
        SqlDataReader myReader;
        myReader = myCommand.ExecuteReader();
        // Always call Read before accessing data.
        if(myReader.Read()) 
        {
           textbox1.Text= myReader.GetString(1);//赋值
        }
        // always call Close when done reading.
        myReader.Close();
        // Close the connection when done with it.
        myConnection.Close();
      

  3.   

    select @t=cast(isnull(max(id),0)+1 as varchar(30)) from yourTable但是,设置一个string类型的t,何必呢?
      

  4.   

    另外,要说清楚t是数据库变量还是应用程序变量。应用程序通常比数据库程序繁琐、效率低。在应用程序中,要使用SqlCommand查询"select isnull(max(id),0)+1 from yourTable",取得 ((int)myCommand.ExecuteScalar()).ToString()。
      

  5.   

    select id, cast(id+1 as varchar(50)) as t