问题描述
- winfopm程序实现sqlserver数据库表传值
-
现有2张表 :A、B都在数据库C中 sqlserver数据库
A(ID、Name、Age、Account)
B(UserID、Name、Age、Account)
现在 A表中 只有 ID 、 Name有全部信息,Age、Account 只有部分有信息,B表每项都有全部信息,A表的Name在B表中都存在,现要把B表的Age、Account值 添加到 A表中没有该值得地方。 请问用 C# winform 该怎么做啊 跪求,急!!!!!!
解决方案
update a set a.age=b.age, a.count = b.count from a,b where a.id=b.userid and (a.age = null or a.account = null)
解决方案二:
update a set a.age=b.age, a.count = b.count from a,b where a.id=b.userid
解决方案三:
string strCon = @"Data Source=Localhost;Database=school;Integrated Security=True";
SqlConnection sqlCon = new SqlConnection(strCon);
sqlCon.Open();
string sql = string.Format("update yProposalMain_ProposalMainFeedbackInfo set yProposalMain_ProposalMainFeedbackInfo.yFeedbackUserGuid=yProposalMain_ProposalMainInfo.yProposerGuid,yProposalMain_ProposalMainFeedbackInfo.yFeedbackUserName=yProposalMain_ProposalMainInfo.yProposerName from yProposalMain_ProposalMainFeedbackInfo,yProposalMain_ProposalMainInfo where yProposalMain_ProposalMainFeedbackInfo.yProposalGuid=yProposalMain_ProposalMainInfo.yProposalGuid and(yProposalMain_ProposalMainFeedbackInfo.yProposalGuid=null or yProposalMain_ProposalMainFeedbackInfo.yFeedbackUserName)");
SqlCommand cmd = new SqlCommand(sql, sqlCon);
int result=cmd.ExecuteNonQuery();
if (result >0 )
{
MessageBox.Show("更新成功");
}
else
{
MessageBox.Show("更新失败");
}
sqlCon.Close();
解决方案四:
and后面加上一个空格看看。
解决方案五:
update yProposalMain_ProposalMainFeedbackInfo set yProposalMain_ProposalMainFeedbackInfo.yFeedbackUserGuid=yProposalMain_ProposalMainInfo.yProposerGuid,yProposalMain_ProposalMainFeedbackInfo.yFeedbackUserName=yProposalMain_ProposalMainInfo.yProposerName from yProposalMain_ProposalMainFeedbackInfo,yProposalMain_ProposalMainInfo where yProposalMain_ProposalMainFeedbackInfo.yProposalGuid=yProposalMain_ProposalMainInfo.yProposalGuid and(yProposalMain_ProposalMainFeedbackInfo.yProposalGuid IS NULL or yProposalMain_ProposalMainFeedbackInfo.yFeedbackUserName)