c# - insert and update sql statement in single sql statement -
i want create insert , update sql statements in single statement. insert statement 1 table , update statement table...
this appliance_location table
create table [dbo].[appliance_location] ( [appliance_id] nchar (10) not null, [roomid] nvarchar (20) not null, [appliancename] nchar (10) not null, [adddate] date null, constraint [pk_appliance_location] primary key clustered ([appliance_id] asc)
);
and appliance_count table
create table [dbo].[appliance_count] ( [roomid] nvarchar (20) not null,`enter code here` [bulb] int not null, [fan] int not null, [ac] int not null, [computer] int not null, constraint [pk_appliance_count] primary key clustered ([roomid] asc)
);
when insert appliance appliance_location table count of particular appliance in appliance_count table should updated
not sure how other sql servers, allowed execute multiple queries using same syntax in ms sql.
using (sqlconnection connection = createconnection()) { sqlcommand command = connection.createcommand(); command.commandtext = @"insert `tablea` values (1, 2, 3); update `tableb` set [val] = 'value' [id] > 10"; command.commandtype = commandtype.text; // ... other initializations return command.executenonquery(); }
you can return values:
insert `tablec` values (1, 'value'); select scope_identity() id;
after query can sql reader , read "id" value response.
why don't try before asking?
Comments
Post a Comment