locked
Cannot Get display RRS feed

  • Question

  • User-373571997 posted
    DAL
    
    using System;
    using System.Data;
    using System.Configuration;
    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 MySql.Data.MySqlClient;
    
    
    public class GlsDal
    {
        //connection to mysql 
        string connStr = String.Format("Server=192.168.1.188;Uid=root;Pwd=root;Database=gls; allow user variables=true");
       
        public GlsDal()
            {
            }
        public int  Insert(string firstName, string lastName)
        {
    
            MySqlConnection conn = new MySqlConnection(connStr);
    
            conn.Open();
    
            MySqlCommand dCmd = new MySqlCommand("Insert INTO customer(ID,FirstName, LastName) Values(@ID, @firstname,@lastname)", conn);
    
            //dCmd.CommandType = CommandType.StoredProcedure;
    
            
            try
            {
    
                dCmd.Parameters.AddWithValue("@firstName", firstName);
    
                dCmd.Parameters.AddWithValue("@lastName", lastName);
    
    
                return dCmd.ExecuteNonQuery();
    
            }
    
            catch
            {
    
                throw;
    
            }
    
            finally
            {
    
                dCmd.Dispose();
                conn.Dispose();
                conn.Close();
                
            }
        }
        public int Select(string firstName, string lastName)
        {
           
    
           MySqlConnection conn1 = new MySqlConnection(connStr);
            conn1.Open();
            MySqlCommand ACmd = new MySqlCommand("Select * From customer ", conn1);
            MySqlDataReader dr = ACmd.ExecuteReader();
            
            try
            {
                if (dr.Read())
                {
    
                    firstName = dr["firstName"].ToString();
                    lastName = dr["lastName"].ToString();
                    //ACmd.Parameters.AddWithValue("@firstName", firstName);
                    //ACmd.Parameters.AddWithValue("@lastName", lastName);
    
                }
                dr.Close();
           return ACmd.ExecuteNonQuery();
          
            }
    
            catch
            {
    
                throw;
    
            }
    
            finally
            {
                
               // ACmd.Dispose();
                conn1.Close();
                //conn1.Dispose();
            }
        
       
        }
    
    }
    
    
    BAL
    
    
    using System;
    using System.Data;
    using System.Configuration;
    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;
    
    
    public class GlsBal
    {
        
    
        public GlsBal()
        {
    
    
    
        }
    
        public int Insert(string firstName, string lastName)
        {
    
            GlsDal gDAL = new GlsDal();
    
            try
            {
    
                return gDAL.Insert(firstName, lastName);
    
            }
    
            catch
            {
    
                throw;
    
            }
    
            finally
            {
    
                gDAL = null;
    
            }
    
        }
    
        public int Select(string firstName, string lastName)
        {
    
            GlsDal gDAL = new GlsDal();
    
            try
            {
    
                return gDAL.Select(firstName, lastName);
    
            }
    
            catch
            {
    
                throw;
    
            }
    
            finally
            {
    
                gDAL = null;
    
            }
    
        }
    }
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using MySql.Data.MySqlClient;
    using GSP_Project;
    using System.Data;
    namespace GSP_Project
    {
      
        public partial class WebForm1 : System.Web.UI.Page
        {
            
            protected void Page_Load(object sender, EventArgs e)
            {
                int intResult = 0;
    
            GlsBal gBAL = new GlsBal();
    
            string firstName = txtFirstName.Text;
    
            string lastName =  txtLastName.Text;
    
             intResult = gBAL.Select(firstName, lastName );
            }
    
            protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
            {
                int intResult = 0;
                if (!Page.IsValid)
    
                    return;
    
            GlsBal gBAL = new GlsBal();
    
            string firstName = txtFirstName.Text;
    
            string lastName =  txtLastName.Text;
    
            try
    
            {
    
                intResult = gBAL.Insert(firstName, lastName );
    
                if (intResult > 0)
                {
                    string script = "alert('The Record Add');";
                    System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Test", script, true);
    
                    txtFirstName.Text ="";
                    txtLastName.Text = "";
                }
                else
                {
                    string script = "alert('The Record No Add');";
                    System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Test", script, true);
                }
    
    
            }
    
            catch (Exception ee)
    
            {
    
              //Label1.Text = ee.Message.ToString();
    
            }
    
            finally
    
            {
    
                gBAL = null;
    
            }        
    
        }
         }
     }
    
    
    
    
    
    can anyone help me , why i cannot display my record in the textbox iziit , the code any wrong ?
    please guide me , i am beginner in asp.net 
    Thursday, July 28, 2011 5:44 AM

Answers

  • User1805528910 posted
     MySqlCommand command = new MySqlCommand(
                        "select * from table1",
                        connection);
                    command.CommandType = CommandType.Text;
    MySqlDataAdapter adapter= new MySqlDataAdapter(cmd); // Fill the DataSet. DataSet dataSet = new DataSet("table1"); adapter.Fill(dataSet);
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2011 1:43 AM

All replies

  • User1805528910 posted

    Hi,

    You are wrong in this fucntion

    public Dataset Select(string firstName, string lastName)
       
    {       

           
    MySqlConnection conn1 = new MySqlConnection(connStr);
            conn1
    .Open();
           
    MySqlCommand ACmd = new MySqlCommand("Select * From customer ", conn1);
           Return
    ACmd.ExecuteDataSet();               
       
       
    }
    Friday, July 29, 2011 4:36 AM
  • User-373571997 posted

      Return ACmd.ExecuteDataSet;

    i get this in error.. 

    Friday, July 29, 2011 5:56 AM
  • User1805528910 posted
     MySqlCommand command = new MySqlCommand(
                        "select * from table1",
                        connection);
                    command.CommandType = CommandType.Text;
    MySqlDataAdapter adapter= new MySqlDataAdapter(cmd); // Fill the DataSet. DataSet dataSet = new DataSet("table1"); adapter.Fill(dataSet);
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2011 1:43 AM