惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
宝玉的分享
宝玉的分享
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
Help Net Security
Help Net Security
腾讯CDC
Project Zero
Project Zero
C
CXSECURITY Database RSS Feed - CXSecurity.com
IT之家
IT之家
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Threatpost
N
News | PayPal Newsroom
C
Cybersecurity and Infrastructure Security Agency CISA
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
SegmentFault 最新的问题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
B
Blog RSS Feed
Forbes - Security
Forbes - Security
P
Privacy & Cybersecurity Law Blog
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
P
Proofpoint News Feed
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog
阮一峰的网络日志
阮一峰的网络日志
aimingoo的专栏
aimingoo的专栏
T
Tenable Blog
MyScale Blog
MyScale Blog
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
W
WeLiveSecurity
D
DataBreaches.Net
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
罗磊的独立博客
The Last Watchdog
The Last Watchdog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Vulnerabilities – Threatpost
美团技术团队
Microsoft Security Blog
Microsoft Security Blog

博客园 - sojay

凡客诚品的跨域获取cookies方法 jquery 飞入购物车效果 SQL2005 中 &quot;SQL_Latin1_General_CP1_CI_AS&quot; 和 &quot;Chinese_PRC_CI_AS&quot; 之间的排序规则冲突 asp.net下载文件的常用方法大全 - sojay - 博客园 IE8下ewebeditor编辑器不能使用的解决办法 - sojay - 博客园 Asp.net SEO优化,针对<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value=""> - sojay 在使用UpdatePanel时JS对话框出错的解决办法。 获取Repeater中Footer/HeaderTemplate 中的控件 repeater嵌套 - sojay - 博客园 用css进行导航定位 导航栏标签定位 - sojay - 博客园 (转)才几百K的eWebEditor v4.6 For asp.net编辑器 各种 Lightbox 效果的实现 XP中IIS“http500”错误的终极解决方法 Application, Session, Cookie, Viewstate, Cache对象用法和区别(转) 转载 .NET牛人应该知道些什么?备忘 学习 应用 我的毕业设计 修改MD5加密 提高网站安全 对google个性主页的拖拽效果的js的完整注释
(原)ASP.NET中的单引号和双引号 - sojay - 博客园
sojay · 2008-03-26 · via 博客园 - sojay

最近做的一个仓库管理(OA)系统遇到的问题
我需要使用下拉菜单读取数据库整条的记录,进行运算,代码如下.但是运行老是出错.找了一天时间才找出错误,少了一对单引号

<%@ Page Language="C#" AutoEventWireup="true"  EnableSessionState="True" CodeFile="test.aspx.cs" Inherits="Web_test" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    
<title></title>
</head>
<body>
    
<form id="form1" runat="server">       
    
<div> 
    
<asp:Label ID="info11" runat="server" Text="Label"></asp:Label>
    
<asp:DropDownList ID="L_GoodsName" runat="server" 
              DataTextField
="info2" DataValueField="info_id" Width="197px" AutoPostBack="True" OnSelectedIndexChanged="L_GoodsName_SelectedIndexChanged" DataSourceID="SqlDataSource1" AppendDataBoundItems="true">
              
<asp:ListItem Value="" Selected="True">==请选择==</asp:ListItem>
          
</asp:DropDownList>
        
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
       
</div>
        
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"></asp:SqlDataSource>
    
</form>
</body>
</html>

test.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Web_test : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
//if (!IsPostBack)
        
//

            SqlDataSource1.SelectCommand 
= "SELECT * FROM [r_ware] ORDER BY [info_id] DESC"//选择商品菜单
            string num = GetNum();
            
this.info11.Text = num;

            GetNum();
        
//}
        
//==================

        
//存放信息 
        
//Application["UserNameID"]="1000"; 
        
//读取信息 
        
//String TextBox1= Application["UserNameID"].ToString();
    }

    
protected void L_GoodsName_SelectedIndexChanged(object sender, EventArgs e)
    
{
        
string info_id = L_GoodsName.SelectedValue;//获得此商品的ID 


        SqlConnection conn 
= new SqlConnection(ConfigurationManager.AppSettings["DBConnectionString"]);
        conn.Open();
        SqlCommand cmd 
= new SqlCommand("select * from r_ware where info_id = " + info_id + " ", conn);
        SqlDataReader my 
= cmd.ExecuteReader();

        
if (my.Read())
        
{

            TextBox1.Text 
= my["info7"].ToString();
            TextBox2.Text 
= my["info10"].ToString();
            
// L_GoodsSum.Text = my["info"].ToString();
        }


        my.Close();

        
//Response.Write(((DropDownList)sender).SelectedItem);

    }

   
    
public String GetNum()
    
{
            Application[
"id"= L_GoodsName.SelectedValue;
            
string id = Application["id"].ToString();
            String Result 
= null;
            SqlConnection conn 
= new SqlConnection(ConfigurationManager.AppSettings["DBConnectionString"]);
            conn.Open();
            SqlCommand cmd 
= new SqlCommand("select info7*info10 from r_ware where info_id = " + id + " ", conn);
            SqlDataReader my 
= cmd.ExecuteReader();
            
if (my.HasRows)
            
{
                
if (my.Read())
                
{
                    Result 
= my[0].ToString();
                }

            }

            conn.Close();
            
return Result;     
    }

  

    
protected void Button1_Click(object sender, EventArgs e)
    
{
  
    }

}

改.CS中的代码
"select info7*info10 from r_ware where info_id = '" + id + "' "
这里需要多一对单引号。。。到处测试成功 之前请教了网上好多人和公司的同事都没找到解决 看来今天又多学了东西 回去再看看书本吧 ^0^