sql语句错误吗?asp.net插入新记录问题
<%@PageLanguage="VB"MasterPageFile="MasterPage.master"Title="add.aspx"%><%@ImportName...
<%@ Page Language="VB" MasterPageFile="MasterPage.master"
Title="add.aspx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<script Runat="server">
Sub add(ByVal Sender As Object, ByVal E As EventArgs)
Dim objCon As OleDbConnection
Dim objCmd As OleDbCommand
Dim strSQL, strDbCon, idno As String
' OLEDB提供者字符串
strDbCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("products.mdb")
objCon = New OleDbConnection(strDbCon)
objCon.Open() ' 打开数据库连接
' 建立添加订单的SQL命令
strSQL = "SELECT Count(*) FROM products"
objCmd = New OleDbCommand(strSQL, objCon)
idno = objCmd.ExecuteScalar() + 1
strSQL = "INSERT INTO products (id,name,type,color,weight,price,information) VALUES (5, 'name.Text','type.Text','color.txt','weight.txt','price.txt','information.txt')"
' 建立Command对象的SQL命令
objCmd = New OleDbCommand(strSQL, objCon)
objCmd.ExecuteNonQuery() ' 添加记录
objCon.Close() ' 关闭数据库连接
End Sub
'麻烦老师帮忙看下为什么插入不了数据库,老是出现insert语法错误?
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="content"
Runat="server"> 名称:<asp:TextBox ID="name" runat="server"></asp:TextBox><br />
类型:<asp:DropDownList ID="type" runat="server" DataSourceID="AccessDataSource1"
DataTextField="type" DataValueField="type">
</asp:DropDownList><asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/products.mdb"
SelectCommand="SELECT [type] FROM [type]"></asp:AccessDataSource>
<br />
颜色:<asp:TextBox ID="color" runat="server"></asp:TextBox><br />
重量:<asp:TextBox ID="weight" runat="server"></asp:TextBox><br />
价格:<asp:TextBox ID="price" runat="server"></asp:TextBox><br />
描述:<asp:TextBox ID="information" Rows=4 runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="添加" OnClick="add"/>
</asp:Content> 展开
Title="add.aspx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<script Runat="server">
Sub add(ByVal Sender As Object, ByVal E As EventArgs)
Dim objCon As OleDbConnection
Dim objCmd As OleDbCommand
Dim strSQL, strDbCon, idno As String
' OLEDB提供者字符串
strDbCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("products.mdb")
objCon = New OleDbConnection(strDbCon)
objCon.Open() ' 打开数据库连接
' 建立添加订单的SQL命令
strSQL = "SELECT Count(*) FROM products"
objCmd = New OleDbCommand(strSQL, objCon)
idno = objCmd.ExecuteScalar() + 1
strSQL = "INSERT INTO products (id,name,type,color,weight,price,information) VALUES (5, 'name.Text','type.Text','color.txt','weight.txt','price.txt','information.txt')"
' 建立Command对象的SQL命令
objCmd = New OleDbCommand(strSQL, objCon)
objCmd.ExecuteNonQuery() ' 添加记录
objCon.Close() ' 关闭数据库连接
End Sub
'麻烦老师帮忙看下为什么插入不了数据库,老是出现insert语法错误?
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="content"
Runat="server"> 名称:<asp:TextBox ID="name" runat="server"></asp:TextBox><br />
类型:<asp:DropDownList ID="type" runat="server" DataSourceID="AccessDataSource1"
DataTextField="type" DataValueField="type">
</asp:DropDownList><asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/products.mdb"
SelectCommand="SELECT [type] FROM [type]"></asp:AccessDataSource>
<br />
颜色:<asp:TextBox ID="color" runat="server"></asp:TextBox><br />
重量:<asp:TextBox ID="weight" runat="server"></asp:TextBox><br />
价格:<asp:TextBox ID="price" runat="server"></asp:TextBox><br />
描述:<asp:TextBox ID="information" Rows=4 runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="添加" OnClick="add"/>
</asp:Content> 展开
展开全部
strSQL = "INSERT INTO products (id,name,type,color,weight,price,information) VALUES (5, 'name.Text','type.Text','color.txt','weight.txt','price.txt','information.txt')"
这里问题很严重
改成
strSQL = "INSERT INTO products (id,name,type,color,weight,price,information) VALUES (5, '" + name.Text + "','" + type.Text + "','" + color.txt + "','" + weight.txt + "','" + price.txt + "','" + information.txt + "')"
这里问题很严重
改成
strSQL = "INSERT INTO products (id,name,type,color,weight,price,information) VALUES (5, '" + name.Text + "','" + type.Text + "','" + color.txt + "','" + weight.txt + "','" + price.txt + "','" + information.txt + "')"
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询