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

推荐订阅源

WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
小众软件
小众软件
Recent Announcements
Recent Announcements
博客园 - 三生石上(FineUI控件)
Security Archives - TechRepublic
Security Archives - TechRepublic
W
WeLiveSecurity
Cloudbric
Cloudbric
博客园 - 司徒正美
美团技术团队
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
PCI Perspectives
PCI Perspectives
宝玉的分享
宝玉的分享
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
Last Week in AI
Last Week in AI
S
Schneier on Security
N
News | PayPal Newsroom
B
Blog RSS Feed
L
LINUX DO - 最新话题
T
Troy Hunt's Blog
S
Secure Thoughts
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
L
Lohrmann on Cybersecurity
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tenable Blog
S
Securelist
L
LangChain Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
InfoQ
H
Heimdal Security Blog
Cisco Talos Blog
Cisco Talos Blog
F
Full Disclosure
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
K
Kaspersky official blog
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
C
Cisco Blogs

博客园 - 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^