将一组结果存储为SQL表中的不同行 [英] Storing a set of results as different rows in SQL table

查看:73
本文介绍了将一组结果存储为SQL表中的不同行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台应用程序(C#),它在运行foreach循环后返回3个不同结果的动态数。现在,我想将它们存储在SQL表中。假设控制台返回的值如,

名称=约翰,年龄= 23,地点=加州

名称=罗伊,年龄= 24,地方=加尔各答

Name = Raul,Age = 23,Place = Spain。



我可以将它存储在SQL表中,如:



名字年龄地点

约翰福音23加州

罗伊24加尔各答

劳尔23西班牙

I have a console application(C#) which returns dynamic number of 3 different results after running a foreach loop. Now, I want to store those in a SQL table. Say the console returns values like,
Name = John, Age= 23, Place= California
Name= Roy, Age= 24, Place= Calcutta
Name= Raul, Age=23, Place= Spain.

Can I stored this in SQL table like:

Name Age Place
John 23 California
Roy 24 Calcutta
Raul 23 Spain

推荐答案

在sql中创建一个包含所需列的表。例如:



create a table in sql with the columns you need. For example:

CREATE TABLE [dbo].[myTableName](
    [s_serial] [int] IDENTITY(1,1) NOT NULL,
    [name] [char](15) NULL,
    [age] [int] NULL,
    [place] [char](50) NULL,
) ON [PRIMARY]

GO





在循环的每次迭代中插入如下值:





on each iteration of the loop insert the values something like:

insert into myTableName values( nameVariable, ageVariable, placeVariable)


这篇关于将一组结果存储为SQL表中的不同行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆