December, 2008

...now browsing by month

 

Quickie - Import Database to MYSQL via SSH/Linux

Friday, December 12th, 2008

Here is a quickie for importing an sql file to mysql on linux….

mysql -u -p dbname < sqlfile

Example

> mysql -u root -p wordpress_db < "/home/webster/backup.sql"
> Enter Password:

And there you have it…

Yakuza

Wednesday, December 10th, 2008
Yakuza provides a telling story and game experience for PS2 gamers.

Yakuza provides a telling story and game experience for PS2 gamers.

So, I found this in the Gamestop pre-played rack.

Now if I could only find time to play it….

Connecting to MySQL through C#

Monday, December 8th, 2008

Just incase some of you aren’t a big fan of MS SQL, or you have MySQL at your disposal and want to use it with your .NET Applications:

In this scenario, I’m using an ancient build of MySQL 4.0.

Download MyODBC 3.51

Setting up MyODBC

  • Run the MSI file
  • Once complete go to Start>Control Panel>Administrative Tools>Data Sources (ODBC)
  • Click Add
  • Choose MySQL ODBC 3.51 Driver
  • Now you may setup various information, such as host, user, pass, database, etc.

Connection Specifics

  • Datasource name - what you will call the connection
  • Description - description of connection (not necessarily needed)
  • Server - localhost
  • username - username of mysql
  • password - password of mysql
  • database - select the database you want to use with this connection

From there you may test your connection to see if everything works.

C# code for connecting and having fun.

What we will want to do first is call our system namespaces that will be required (Data, Data.Odbc, Data.SqlClient). However, you may call a few more references for other reasons, such as I have in the example:

using System;
using System.Data;
using System.Data.Odbc;
using System.Data.SqlClient;
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;

From there we will want to create a method for the data retrieval. We will call this Build_Record().

public void Build_Record()
{
//Setup our connection string referring to our ODBC connection
OdbcConnection con = new OdbcConnection(ConfigurationManager.ConnectionStrings["MYSQL"].ConnectionString);

//Format our SQL query
string strSQL = "SELECT name, type, date, credit, debit FROM monthly";

//create a command variable
OdbcCommand com = new OdbcCommand(strSQL, con);

//try the connection and populate the gridview; else fail
try
{
//open connection
con.Open();

//execute the query
com.ExecuteNonQuery();

//alert user (optional)
lblrecordadded.Text = "Success";

//source of the data for the gridview
ITGridView1.DataSource = com.ExecuteReader();

//bind the data
ITGridView1.DataBind();

//close the connection
con.Close();
con.Dispose();
}
catch (Exception e)
{
lblrecordadded.Text = "Error Occured " + e.Message.ToString();
lblrecordadded.Visible = true;
return;
}
con.Close();
}

And then we will move on to call our method in the Page_Load method:

using System;
using System.Data;
using System.Data.Odbc;
using System.Data.SqlClient;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Execute our method upon page load
Build_Record();
}

And a view at the Full C# Code

using System;
using System.Data;
using System.Data.Odbc;
using System.Data.SqlClient;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Execute our method upon page load
Build_Record();
}

public void Build_Record()
{
//Setup our connection string referring to our ODBC connection
OdbcConnection con = new OdbcConnection(ConfigurationManager.ConnectionStrings["MYSQL"].ConnectionString);

//Format our SQL query
string strSQL = "SELECT first, last, date FROM tablename";

//create a command variable
OdbcCommand com = new OdbcCommand(strSQL, con);

//try the connection and populate the gridview; else fail
try
{
//open connection
con.Open();

//execute the query
com.ExecuteNonQuery();

//alert user (optional)
lblrecordadded.Text = "Success";

//source of the data for the gridview
MyGridView.DataSource = com.ExecuteReader();

//bind the data
MyGridView.DataBind();

//close the connection
con.Close();
con.Dispose();
}
catch (Exception e)
{
lblrecordadded.Text = "Error Occured " + e.Message.ToString();
lblrecordadded.Visible = true;
return;
}
con.Close();
}
}

Now, the Gridview could look like this:

<asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="first" HeaderText="First"/>
<asp:BoundField DataField="last" HeaderText="Last" />
<asp:BoundField DataField="date" HeaderText="Date" />
</Columns>
</asp:GridView>

Blackberry post

Monday, December 8th, 2008

So I’ve joined the tech revolution and purchased a blackberry. Now I can really commit to short quickie posts.

Time Crunch

Wednesday, December 3rd, 2008

Lately I’ve been very off topic from the programming blog theme.  Here goes nothing:

The holidays are approaching fast! I’ve found myself very busy with work and travel lately.  Not to worry though, I have everything on track to get a few posts going.  One can expect something by tomorrow on connecting to MySQL via ASP.NET & C Sharp.  Where are the jQuery tutorials?  Those are going to be posted in the next few days as well.

Everyone seems to be worried about the economic “recession” that the United States is experiencing.  Hrmm, I’ll have to take a closer look - seems the recession is causing more contract work to steer my way.  Go economy?

Hope all is well in the Inter-world.  I appreciate your visits and I promise that more on-topic posts are to follow!