试一试
strSQL = "INSERT INTO tablename (name) VALUES (@name);SELECT @@Identity"
SQLCommand.CommandText = strSQL
Id = SQLCommand.ExecuteScalar()

解决方案 »

  1.   

    参数的返回类型是什么呀?还有我的表名infor
      

  2.   

    自增类型的id不是真能Integer吗。INSERT INTO tablename (name) VALUES (@name)换成你自己的插入语句。
    SELECT @@Identity是返回刚插入的记录的ID.
      

  3.   

    string strCommand=" insert infor values('"+TextBox2.Text+" ','"+TextBox3.Text+" ','"+TextBox4.Text+" ','"+TextBox5.Text+" ') ;SELECT @@Identity;";
                    SqlCommand.CommandText = strCommand;
                   Integer Id = SqlCommand.ExecuteScalar();
    我这么写编译总出错。帮忙看看错在哪,谢咯!
      

  4.   


    sql 编译错误,还是C#编译错误?
      

  5.   

    错误提示:
    c:\inetpub\wwwroot\infor1\WebForm1.aspx.cs(228): 非静态的字段、方法或属性“System.Data.SqlClient.SqlCommand.CommandText”要求对象引用c:\inetpub\wwwroot\infor1\WebForm1.aspx.cs(229): 找不到类型或命名空间名称“Integer”(是否缺少 using 指令或程序集引用?)
      

  6.   

    insert into 表(字段)  OUTPUT INSERTED.自增ID values(字段)
      

  7.   

    你那自增加是指SQLSERVER数据库
    top(1)   desc
    max(id)
      

  8.   

    string strCommand=" insert into values('"+TextBox2.Text+" ','"+TextBox3.Text+" ','"+TextBox4.Text+" ','"+TextBox5.Text+" ') ;SELECT @@Identity;";
      

  9.   

    infor,叼炸天
    基本insert语句都忘了
    INSERT INTO 表名称 VALUES (值1, 值2,....)
      

  10.   


    首先没有实例化SqlCommand在一个是直接用 int 类型接收值,哪来的Integer类型
      

  11.   


    insert into 不是 insert infor。
      

  12.   


    .................
                SqlCommand com = new SqlCommand();
                com.CommandText = strCommand;
                int Id =(int)com.ExecuteScalar();
      

  13.   


    不建议用@@Identity  建议用SCOPE_IDENTITY  http://hi.baidu.com/qxyywy/item/dbcc133fe1914a26b2c0c521  以前上一家公司也出现过类似问题