【发布时间】:2015-05-07 11:50:56
【问题描述】:
我创建了两个表:Artist 和 Song。 Artist 表有字段 Artistid 和 ArtistName,Song 表有 SongID、Lyrics、Description 和 Artistid 作为辅助键。我有一个 Web 表单来添加包含文本框和提交按钮的新艺术家。
代码如下:
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" method ="post">
<div style="width: 960px; color: black; border: 2px solid black; text-align:"center">
<table>
<tr>
<td> <label>Artist: </label>
<input type="text" name ="textArtist" id ="txtartist" value = "" />
</td>
</tr>
<tr>
<td>
<p align="center" >
<input type = "button" id= "btnArtist" value ="submit" />
</p>
</td>
</tr>
</table>
</div>
</form>
</body>
我的要求是在文本框中输入一些名字并点击提交,相同的名字应该显示在数据库的艺术家表中。 我还使用 Mygenerations 与艺术家和歌曲表创建了一个名称空间。我已经编写了以下代码,但它没有显示数据库中的数据。它无法正常工作。请帮忙。 文件后面的代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NCI.EasyObjects ;
using TestSong ;
public partial class _Default : System.Web.UI.Page
{
string strcon = "Company";
protected void Page_Load(object sender, EventArgs e)
{
}
void btnartist_onclick(object sender, EventArgs e)
{
string s_artistname = textArtist.Value;
Artist oArtist = new Artist(strcon);
oArtist.Where.ArtistName.Value = s_artistname;
if (!oArtist.Query.Load())
{
oArtist.AddNew();
oArtist.ArtistName = textArtist.Value;
oArtist.Save();
}
}
}
我也收到了包含textArtist.Value 的行的错误。错误是 textArtist 在当前上下文中不存在。请告诉我哪里出错了。
【问题讨论】: