`
索菲亚.  ぅ
  • 浏览: 15815 次
  • 性别: Icon_minigender_2
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

4.16学习笔记

    博客分类:
  • NET
阅读更多

 存储过程:

CREATE PROCEDURE [insert_pinglun]
 (@qyid               [int],
  @content  [ntext],
  @plname  [nvarchar](50),
  @qq               [char](20),
  @email  [nvarchar](50),
  @ip  [char](20),
  @time1  [datetime])

AS INSERT INTO [cne71].[dbo].[pinglun] 
  ( [qyid],
  [content],
  [plname],
  [qq],
  [email],
  [ip],
  [time1]) 
 
VALUES 
 ( @qyid,
  @content,
  @plname,
  @qq,
  @email,
  @ip,
  @time1)
return 1
GO

 数据层代码:(调用存储过程)

public int insertpinglun(qiyeVAO qiyeVO)
  {
   int rowsAffected;
   int returnValue;
   SqlParameter[] Parameters={
            new SqlParameter("@qyid",SqlDbType.Int,6),
            new SqlParameter("@content",SqlDbType.NText),
            new SqlParameter("@plname",SqlDbType.NVarChar,50),
            new SqlParameter("@qq",SqlDbType.Char,20),
            new SqlParameter("@email",SqlDbType.NVarChar,50),
            new SqlParameter("@ip",SqlDbType.Char,20),
            new SqlParameter("@time1",SqlDbType.DateTime)
            };
   Parameters[0].Value=qiyeVO.Id;
   Parameters[1].Value=qiyeVO.Content;
   Parameters[2].Value=qiyeVO.Plname;
   Parameters[3].Value=qiyeVO.Qq;
   Parameters[4].Value=qiyeVO.Email;
   Parameters[5].Value=qiyeVO.Ip;
   Parameters[6].Value=qiyeVO.Time1;

   core.DbObject db1= new DbObject();

   returnValue = (int)db1.RunProcedure("insert_pinglun",Parameters,out rowsAffected);
   return returnValue;

  }


类代码:(core/DbObject .cs)
public class DbObject
 {
  protected SqlConnection Connection;
  private string connectionString;
  public DbObject()
  {
   connectionString = System.Configuration.ConfigurationSettings.AppSettings["sqlConnection"];
   Connection = new SqlConnection( connectionString );
  }
  public SqlCommand BuildIntCommand(string storedProcName,IDataParameter[] parameters)
  {
   SqlCommand command = BuildQueryCommand ( storedProcName,parameters );
   command.Parameters.Add(new SqlParameter("ReturnValue",SqlDbType.Int,4,ParameterDirection.ReturnValue,false,0,0,string.Empty,DataRowVersion.Default,null));
   return command;
  }
  public SqlCommand BuildQueryCommand ( string storedProcName,IDataParameter[] parameters)
  {
   SqlCommand command = new SqlCommand( storedProcName,Connection);
   command.CommandType = CommandType.StoredProcedure;
   foreach ( SqlParameter parameter in parameters )
   {
    command.Parameters.Add( parameter );
    //System.Web.HttpContext.Current.Response.Write( parameter.ParameterName);
    //System.Web.HttpContext.Current.Response.Write( parameter.SqlDbType);
    //System.Web.HttpContext.Current.Response.Write( parameter.Value);
   }
   //System.Web.HttpContext.Current.Response.Write (command.Parameters.Count);
   return command;
  }
  protected string ConnectionString
  {
   get 
   {
    return connectionString;
   }
  }
  public  int RunProcedure ( string storedProcName ,IDataParameter[] parameters, out int rowsAffected )
  {

   int result;
   Connection.Open();
   SqlCommand command = BuildIntCommand ( storedProcName ,parameters );
   rowsAffected = command.ExecuteNonQuery();//没有影响就是-1
   result = (int)command.Parameters["ReturnValue"].Value;
   Connection.Close();
   Connection.Dispose();
    
   return result;
  }
 }

 =================================================

DropDownList--ListBox--CheckBoxList--RadioButtonList:ListItem

向ListBox中添加条目

ListBox1.Items.Add(new ListItem("Olivne","MG2SIO4"));

 

 

输出ListBox中多个选中项
===
.aspx
===

<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple">
            <asp:ListItem>Hematite</asp:ListItem>
            <asp:ListItem>Halite</asp:ListItem>
            <asp:ListItem>Limonite</asp:ListItem>
            <asp:ListItem>Magnetite</asp:ListItem>
</asp:ListBox>

 ===
.cs
===

Label3.Text="You selected from ListBox:<br>";
        foreach (ListItem li in ListBox1.Items)
        {
            if (li.Selected == true)
            {
                Label3.Text += li.Text + "</br>";
            }
        }

 确定复选框是否被选中

if(CheckBox1.checked==true){}

 
给复选框赋值

CheckBox1.checked=true;

 

1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics