不使用gridview从数据库更新数据的代码 [英] Code for Updating data from database not using gridview

查看:76
本文介绍了不使用gridview从数据库更新数据的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用项目的列表框和文本框进行更新的C#代码(存储过程,DAL,BAL和UI)进行更新

存储过程

C# code for updating(stored procedure,DAL,BAL and UI)using listbox for items and textbox to update

Stored procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[p_UpdateMainQ]

@MainQuestionId VARCHAR (50)

AS

UPDATE MAINQUESTION
SET SurveyId=@MainQuestionId
WHERE MainQuestion =MainQuestion



DAL代码



DAL code

public int UpdateMainQuestion(string MainQuestion)
        {
            //using (SqlConnection connection = new SqlConnection(connectionInfo))
            //{
            //    connection.Open();
            //    SqlDataReader myReader = null;
            //    SqlCommand myCommand = new SqlCommand("p_UpdateMainQ", connection);
            //    myCommand.CommandType = CommandType.StoredProcedure;
            //    myCommand.Parameters.Add(new SqlParameter("@MainQuestion", MainQuestion));
            //    myReader = myCommand.ExecuteReader();

            //    if (myReader.Read())
            //    {

            //        //txtMQ.Text = myReader[1].ToString();


            //    }
            //}

            SqlConnection conn = new SqlConnection(connectionInfo);
            conn.Open();
            SqlCommand dCmd = new SqlCommand("p_UpdateMainQ", conn);
            dCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                //dCmd.Parameters.AddWithValue("@MainQuestionId", MainQuestionId);
               // dCmd.Parameters.AddWithValue("@SurveyId", 1);
                dCmd.Parameters.AddWithValue("@MainQuestion", MainQuestion);

                return dCmd.ExecuteNonQuery();
            }
            catch
            {
                throw;
            }
            finally
            {
                dCmd.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }



BAL代码



BAL code

public int UpdateMainQuestion(string MainQuestion)
      {
         return  MQDAL.UpdateMainQuestion(MainQuestion);
      }




用户界面代码




UI code

try
               {
                   string Ques = lstMainQ.SelectedItem.ToString();
                   txtMain.Text = Ques;
                   txtMain.Focus();
                   int Index = lstMainQ.SelectedIndex;
                   lstMainQ.Items.RemoveAt(lstMainQ.SelectedIndex);
                   String MainQuestion = txtMain.Text;
                   MainQuestionBAL MQBAL = new MainQuestionBAL();
                 int MQ=  MQBAL.UpdateMainQuestion(MainQuestion);
                 if (MQ.Equals(1))
                 {
                 }

推荐答案



请参阅以下链接
http://aspdotnetcodebook.blogspot.in/2010/09/3-tier- architecture-in-aspnet.html [ ^ ]

http://www.c-sharpcorner.com/uploadfile/paulabraham/building3tierapppa11282005053625am/building3tierapppa.aspx [ ^ ]

祝你好运
Hi,

refer following links
http://aspdotnetcodebook.blogspot.in/2010/09/3-tier-architecture-in-aspnet.html[^]

http://www.c-sharpcorner.com/uploadfile/paulabraham/building3tierapppa11282005053625am/building3tierapppa.aspx[^]

Best luck


这篇关于不使用gridview从数据库更新数据的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆