提示:
不存在从对象类型 System.Web.UI.WebControls.TextBox 到已知的托管提供程序本机类型的映射。
下面是Button1_Click方法往start的weblink表添加数据
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlconn1 = new SqlConnection("server=.;database=start;uid=sa;pwd=");//连接字符串
string insertlink = "insert into weblink(weblink,webname)values(@link,@name)";
SqlCommand insertcmd = new SqlCommand(insertlink,sqlconn1);
insertcmd.Parameters.Add("@link",link);//可能是这两行出错误了
insertcmd.Parameters.Add("@name",name);
sqlconn1.Open();
int result = insertcmd.ExecuteNonQuery();
sqlconn1.Close();
}
这里是表现层的代码,两个TEXTBOX:link,name 一个按钮 Button1,产生事件 Button1_Click
<asp:Label ID="Label1" runat="server" Style="z-index: 105; left: 16px; position: absolute;
top: 312px" Text="站名" Width="40px"></asp:Label>
<asp:TextBox ID="name" runat="server" Style="z-index: 106; left: 56px; position: absolute;
top: 312px" Width="168px"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Style="z-index: 107; left: 16px; color: #0000ff;
position: absolute; top: 288px" Text="输入网站名和链接地址" Width="208px"></asp:Label>
<asp:Button ID="Button1" runat="server" Style="z-index: 108; left: 160px; color: #0000ff;
position: absolute; top: 360px" Text="添加快链" Width="70px" OnClick="Button1_Click" />
<asp:TextBox ID="link" runat="server" Style="z-index: 109; left: 56px; position: absolute;
top: 336px" Width="168px"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Style="z-index: 110; left: 16px; position: absolute;
top: 336px" Text="地址" Width="40px"></asp:Label>
不存在从对象类型 System.Web.UI.WebControls.TextBox 到已知的托管提供程序本机类型的映射。
下面是Button1_Click方法往start的weblink表添加数据
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlconn1 = new SqlConnection("server=.;database=start;uid=sa;pwd=");//连接字符串
string insertlink = "insert into weblink(weblink,webname)values(@link,@name)";
SqlCommand insertcmd = new SqlCommand(insertlink,sqlconn1);
insertcmd.Parameters.Add("@link",link);//可能是这两行出错误了
insertcmd.Parameters.Add("@name",name);
sqlconn1.Open();
int result = insertcmd.ExecuteNonQuery();
sqlconn1.Close();
}
这里是表现层的代码,两个TEXTBOX:link,name 一个按钮 Button1,产生事件 Button1_Click
<asp:Label ID="Label1" runat="server" Style="z-index: 105; left: 16px; position: absolute;
top: 312px" Text="站名" Width="40px"></asp:Label>
<asp:TextBox ID="name" runat="server" Style="z-index: 106; left: 56px; position: absolute;
top: 312px" Width="168px"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Style="z-index: 107; left: 16px; color: #0000ff;
position: absolute; top: 288px" Text="输入网站名和链接地址" Width="208px"></asp:Label>
<asp:Button ID="Button1" runat="server" Style="z-index: 108; left: 160px; color: #0000ff;
position: absolute; top: 360px" Text="添加快链" Width="70px" OnClick="Button1_Click" />
<asp:TextBox ID="link" runat="server" Style="z-index: 109; left: 56px; position: absolute;
top: 336px" Width="168px"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Style="z-index: 110; left: 16px; position: absolute;
top: 336px" Text="地址" Width="40px"></asp:Label>
解决方案 »
- IIS中搭建了一个Site,browser之后出现下面效果,希望提供下有效解方案
- 一个很简单的东西令我非常郁闷不解
- ASP.NET 2.0 Profile谁使用过啊
- 更新XML格式的多条记录的问题?
- 请问如何绑定Repeater里的Lable控件
- 水晶報表問題?
- 求助:用window.showModalDialog时,ASP.NET中子窗口如何操作传递过来的window.dialogArguments(JS)这个值!!!!
- 请教: 为何我的 ListBox1_SelectedIndexChanged 事件不能触发? 只有在点击任意一个按钮后才刷新 label1 的值?
- 怎样用asp.net+c#动态生成导航条?虚心请教!
- 水晶报表字段有值传过来,但就是运行不显示,烦请各位老大来帮忙帮忙
- 电子地图是怎么做的
- 不允许从数据类型 varchar 到 varbinary 的隐式转换。请使用 CONVERT 函数来运行此查询。
insertcmd.Parameters.Add("@name",name);
==
insertcmd.Parameters.AddWithValue("@link",link.Text);
insertcmd.Parameters.AddWithValue("@name",name.Text);
insertcmd.Parameters.Add("@name",name);
link 和 name 是控件的ID应该获得它的Text。
所以应该写成
insertcmd.Parameters.Add("@link",link.Text);
insertcmd.Parameters.Add("@name",name.Text);
在asp.net2.0里面Add函数已经过时建议使用AddWithValue。就是1楼的同志写的。