怎么把A表中的数据插入到B表中

qq346291119 2011-12-01 06:26:51

数据库有 表A 表B

表A:

id name phone number


表B:
id number
1 FDGGDS
2 DFDGFD
3 DSFSDD
4 DSFSDF
5 SDFSDF

表A是注册表 需要填的字段是name 跟phone 然后保存的时候需要从表B里面取number的字段 保存到表A的Number中
按照顺序依次往下取值

我是菜鸟求指教...
...全文
614 41 打赏 收藏 转发到动态 举报
写回复
用AI写文章
41 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq346291119 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 39 楼 sandy945 的回复:]
select top 1 number tableName 有值么
[/Quote]

有值的 number字段的是第一条数据
阿非 2011-12-02
  • 打赏
  • 举报
回复
select top 1 number tableName 有值么
qq346291119 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 37 楼 sandy945 的回复:]
插入什么数据?

你一次多说点
[/Quote]

string sql = "select top 1 number tableName tb where not exists(select 1 from UserKTV where number=tb.number)";

直接在程序里面运行 这个sql取不到值的 因为number=tb.number 中的number没有值

怎么取到这个值 然后赋给number啊
阿非 2011-12-02
  • 打赏
  • 举报
回复
插入什么数据?

你一次多说点
qq346291119 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 sandy945 的回复:]
C# code
string sql = "select top 1 number tableName tb where not exists(select 1 from UserKTV where number=tb.number)";

string number = (string)SqlHelper.ExecuteScalar(SqlHelper.AppConnectionStrin……
[/Quote]

怎么把数据插到这句sql中的number里啊
qq346291119 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 34 楼 sandy945 的回复:]
sql语句 在数据库中能查到记录么
[/Quote]

我找到原因了 因为number 没有数据
阿非 2011-12-02
  • 打赏
  • 举报
回复
sql语句 在数据库中能查到记录么
qq346291119 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 32 楼 sandy945 的回复:]
tableName 你换成你自己的表名了么?
[/Quote]

换了
阿非 2011-12-02
  • 打赏
  • 举报
回复
tableName 你换成你自己的表名了么?
qq346291119 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 30 楼 sandy945 的回复:]
string number = (string)SqlHelper.ExecuteScalar(SqlHelper.AppConnectionString, CommandType.Text, sql, para);

看看ExecuteScalar 这个方法有没有三个参数的重载

string number = (string)SqlHelper.ExecuteScalar(SqlHel……
[/Quote]

第一次number的数据怎么得到啊 现在number没有数据啊
阿非 2011-12-02
  • 打赏
  • 举报
回复
string number = (string)SqlHelper.ExecuteScalar(SqlHelper.AppConnectionString, CommandType.Text, sql, para);

看看ExecuteScalar 这个方法有没有三个参数的重载

string number = (string)SqlHelper.ExecuteScalar(SqlHelper.AppConnectionString, CommandType.Text, sql); 这样形式的


qq346291119 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 27 楼 sandy945 的回复:]
什么字段下面的值?
[/Quote]

查询出来number了 可是下面的数据没有啊
c02645 2011-12-02
  • 打赏
  • 举报
回复
insert into A (id,name,phone,number) select 1,'name','phone',number from B b
where b.id=1
阿非 2011-12-02
  • 打赏
  • 举报
回复
什么字段下面的值?
qq346291119 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 24 楼 sandy945 的回复:]
string sql = "select top 1 number from tableName tb where not exists(select 1 from UserKTV where number=tb.number)";
[/Quote]

查出来这个字段了 可是字段下面的值没有出来

是怎么回事啊
zmkkobe 2011-12-02
  • 打赏
  • 举报
回复
跟着阿非学习sql
阿非 2011-12-02
  • 打赏
  • 举报
回复
string sql = "select top 1 number from tableName tb where not exists(select 1 from UserKTV where number=tb.number)";

qq346291119 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 sandy945 的回复:]
C# code
string sql = "select top 1 number tableName tb where not exists(select 1 from UserKTV where number=tb.number)";

string number = (string)SqlHelper.ExecuteScalar(SqlHelper.AppConnectionStrin……
[/Quote]


tb附近有语法错误啊
阿非 2011-12-02
  • 打赏
  • 举报
回复
string sql = "select top 1 number tableName tb where not exists(select 1 from UserKTV where number=tb.number)";

string number = (string)SqlHelper.ExecuteScalar(SqlHelper.AppConnectionString, CommandType.Text, sql, para);

return number;

类似这样
qq346291119 2011-12-02
  • 打赏
  • 举报
回复

现在要把这个号码 改成从另一张表里面读取出来

加载更多回复(20)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧