简体   繁体   中英

I can't insert a record in database: "Invalid Column Name"

create PROCEDURE [dbo].[pro_InsertRecord]

      @table      varchar(30)   , 
      @field      varchar(max)  ,
      @value      varchar(max)
AS
SET NOCOUNT ON

BEGIN

 EXEC('INSERT INTO ' + @table + '(' + @field + ') VALUES ( '+ @value +')')

END

I can't insert a record in database but i receive an insert error message as "Invalid Column Name"

my code:

string fieldnames = "Login_UserName, Login_Password, Login_Role_Id";

  string fieldvalues =  UserName +"','" + Password + "'," + Role ; 

com.Common.InsertRecord("Login", fieldnames, fieldvalues);

Instead of

string fieldvalues =  UserName +"','" + Password + "'," + Role ; 

use

string fieldvalues = "'" + UserName + "','" + Password + "'," + Role ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM