Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID)values('"&Zhanghubianhao.Text&"','"&ContractID.Text&"','"&ServiceType.Selectedvalue&"','"&AgentID.Selectedvalue&"')"
Zhanghubianhao_Text = Zhanghubianhao.Text ... ...Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID)values('@Zhanghubianhao_Text','@ContractID_Text','@ServiceType_Selectedvalue','@AgentID_Selectedvalue')"
Zhanghubianhao_Text = Zhanghubianhao.Text ... ...Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID)values('@Zhanghubianhao_Text','@ContractID_Text','@ServiceType_Selectedvalue','@AgentID_Selectedvalue')" ========== 错! 第一楼主要求不要其它变量 第二即使你使用参数,也不应该在双引号吧?Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID)values(@Zhanghubianhao_Text,@ContractID_Text,@ServiceType_Selectedvalue,@AgentID_Selectedvalue)"我认为应该这样!
Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID) values ('"&Zhanghubianhao.Text&"','"&ContractID.Text&"','"&ServiceType.Selectedvalue&"','"&AgentID.Selectedvalue&"')"你看看什么错误,单步调试一下,看看字符串是什么,就很容易找到错误了 注意一下你的ServiceType.Selectedvalue,和AgentID.Selectedvalue看看对么?values前后要有空格吧?
这样不好,容易被SQL注入.应改为参数方式: Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID)values(@Zhanghubianhao,@ContractID,@ServiceType,@AgentID)" 然后: dim cmd as new SqlCommand(); cmd.Parameter.Add("@Zhanghubianhao",Zhanghubianhao.Text.Trim()) ...
...
...Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID)values('@Zhanghubianhao_Text','@ContractID_Text','@ServiceType_Selectedvalue','@AgentID_Selectedvalue')"
...
...Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID)values('@Zhanghubianhao_Text','@ContractID_Text','@ServiceType_Selectedvalue','@AgentID_Selectedvalue')"
==========
错!
第一楼主要求不要其它变量
第二即使你使用参数,也不应该在双引号吧?Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID)values(@Zhanghubianhao_Text,@ContractID_Text,@ServiceType_Selectedvalue,@AgentID_Selectedvalue)"我认为应该这样!
注意一下你的ServiceType.Selectedvalue,和AgentID.Selectedvalue看看对么?values前后要有空格吧?
Response.Write(StrCmd2);
把输出的Sql语句拷贝到查询分析器中,就很清楚了。
Dim StrCmd2 As String="insert into ContractInfo(Zhanghubianhao,ContractID,ServiceType,AgentID)values(@Zhanghubianhao,@ContractID,@ServiceType,@AgentID)"
然后:
dim cmd as new SqlCommand();
cmd.Parameter.Add("@Zhanghubianhao",Zhanghubianhao.Text.Trim())
...