---------- Forwarded message ----------
From: Praveen Kumar <[EMAIL PROTECTED]>
Date: Mar 14, 2008 11:33 AM
Subject: GridView with Mono Server
To: [email protected]

Hello all and one,
For me Its a great acchievement i have completely configured MONO, .net with
MySql running in ubuntu os. now i can run my .Net2.0 Project on Ubuntu OS.
But i stucked in my project while i am using GridView. I am not able to bind
GridView with records. i have applied all the way by using
DataReader,DataAdapter,DataTable but could not succeed. i have attached my
code with this mail. please do check.
i am compiling my login.aspx.cs with gmcs compiler


using System;
using System.Data;
using System.Data.Common;
using System.ComponentModel;
using System.Drawing;
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.Web.SessionState;
//using System.Data.Odbc;
using MySql.Data.MySqlClient;

namespace Demo
{
public class data : System.Web.UI.Page
{
GridView GridView1;

     protected void Page_Load(object sender, EventArgs e)
        {
        test();
        Page.Response.Write(" Me called on page Load");
        //txt_username.Text="Hi";
        }
    override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form
Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
    private void InitializeComponent()
        {
            //this.btn_password.Click += new System.EventHandler(
this.btn_password_Click);
            //this.Button1.Click += new System.EventHandler(
this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }
    public void test()
    {

        /*IDataReader reader;
        IDbConnection dbcon;
        IDbCommand dbcmd;*/
        MySqlDataReader reader;
        MySqlConnection dbcon;
        MySqlCommand dbcmd;
        MySqlDataAdapter da;
GridView1=new GridView();
        DataTable dt;
        DataSet ds;
        try
        {
            string connectionString =
                  "Server=192.168.2.140;" +
                  "Database=employee;" +
                  "User ID=praveen;" +
                  "Password=;" +
                  "Pooling=false";
                   dbcon = new MySqlConnection(connectionString);
                   dbcon.Open();
                   //dbcmd = dbcon.CreateCommand();
                string sql =
                   "SELECT firstname, lastname " +
                   "FROM employee";
                   //dbcmd.CommandText = sql;
            dbcmd=new MySqlCommand(sql,dbcon);
GridView1.DataSource=dbcmd.ExecuteReader();
GridView1.DataBind();
GridView gv=(GridView)FindControl("GridView1");
        Page.Response.Write(gv);
//da=new MySqlDataAdapter(sql,dbcon);
//da.Fill(ds);
//GridView1.DataSource=ds;
//GridView1.DataBind();
                   //reader = dbcmd.ExecuteReader();
            //Page.Response.Write(reader);
                   /*while(reader.Read())
            {
                //GridView1.DataSource=reader["firstname"];
                //GridView1.DataBind();
                        string FirstName = (string) reader["firstname"];
                        string LastName = (string) reader["lastname"];
                        Page.Response.Write("Name: " +
                          FirstName + " " + LastName);

            }// end of while*/

        }//end of try
        catch(Exception e1)
        {
            Page.Response.Write(e1);
        }//end of catch
        finally{

            }//end of finally

    }// end of test
   /*private void Button1_Click(object sender, EventArgs e)
    {
        //Login(txt_username.Text, txt_password.Text);
    test();
    }*/

}
}

-- 
Praveen Kumar
Software Engineer
Mahiti Infotech Pvt. Ltd.
# 33-34, Hennur Cross
Hennur Main Road
Bangalore, India - 560043
Mobile:  +91 9343297314
             +91 9739854134
http://www.mahiti.org


-- 
Praveen Kumar
Software Engineer
Mahiti Infotech Pvt. Ltd.
# 33-34, Hennur Cross
Hennur Main Road
Bangalore, India - 560043
Mobile:  +91 9343297314
             +91 9739854134
http://www.mahiti.org

Attachment: login.aspx
Description: Binary data

using System;
using System.Data;
using System.Data.Common;
using System.ComponentModel;
using System.Drawing;
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.Web.SessionState;
//using System.Data.Odbc;
using MySql.Data.MySqlClient;

namespace Demo
{
public class data : System.Web.UI.Page
{
GridView GridView1;

 	protected void Page_Load(object sender, EventArgs e)
    	{
		test();
		Page.Response.Write(" Me called on page Load");
		//txt_username.Text="Hi";
    	}
	override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		
	private void InitializeComponent()
		{    
			//this.btn_password.Click += new System.EventHandler(this.btn_password_Click);
			//this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);
		

		}
		//#endregion

    /*public void Login(string txt_username, string txt_password)
    {

       // clean up
       
        /*string s1 = txt_username;
        string s2 = txt_password;
        int result=0;
        string sql = "SELECT count(*)as rows FROM FK_TBLUSER where NAME='"+s1+"'and PASSWORD='"+s2+"' ";
        cmd = new OdbcCommand(sql, myConn);
        MyReader = cmd.ExecuteReader();
           while (MyReader.Read())
            {
              result=Convert.ToInt32(MyReader["rows"]);
              Page.Response.Write(result);
            }
            if (result == 1)
            {
                Response.Redirect("Home.aspx");
            }
            else
            {
                Response.Write("Wrong user name or password");
            }
        
               MyReader.Close();
               myConn.Close();
    }*/// end of Login function
	public void test()
	{
	
		/*IDataReader reader;
		IDbConnection dbcon;
		IDbCommand dbcmd;*/
		MySqlDataReader reader;
		MySqlConnection dbcon;
		MySqlCommand dbcmd;
		MySqlDataAdapter da;
//GridView1=new GridView();
		DataTable dt;
		DataSet ds;
		try
		{
			string connectionString =
	          	"Server=192.168.2.140;" +
	          	"Database=employee;" +
	          	"User ID=praveen;" +
	          	"Password=;" +
	          	"Pooling=false";
	       		dbcon = new MySqlConnection(connectionString);
	       		dbcon.Open();
	       		//dbcmd = dbcon.CreateCommand();
	        	string sql =
        	   	"SELECT firstname, lastname " +
        	   	"FROM employee";
       			//dbcmd.CommandText = sql;
			dbcmd=new MySqlCommand(sql,dbcon);
//GridView1.DataSource=dbcmd.ExecuteReader();
//GridView1.DataBind();
GridView gv=(GridView)FindControl("GridView1");
		Page.Response.Write(gv);
ds=new DataSet();
da=new MySqlDataAdapter(sql,dbcon);
da.Fill(ds);
GridView1.DataSource=ds;
GridView1.DataBind();
       			//reader = dbcmd.ExecuteReader();
			//Page.Response.Write(reader);
       			/*while(reader.Read()) 
			{
				//GridView1.DataSource=reader["firstname"];
				//GridView1.DataBind();
	            		string FirstName = (string) reader["firstname"];
	            		string LastName = (string) reader["lastname"];
	            		Page.Response.Write("Name: " +
	                  	FirstName + " " + LastName);
				
			}// end of while*/

		}//end of try
		catch(Exception e1)
		{
			Page.Response.Write(e1);
		}//end of catch
		finally{

			}//end of finally

	}// end of test
   /*private void Button1_Click(object sender, EventArgs e)
    {
        //Login(txt_username.Text, txt_password.Text); 
	test();
    }*/
    
}
}
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to