Search This Blog

Tuesday, July 13, 2010

Effective Way to Remove CR LF in MySQL Query

I had a need to replace new lines in a query that was causing issues elsewhere in a process flow that I was working on. While removing the new lines in code would be easy, the problem was that they were needed to designate the end of a line in a file. So, I decided to remove them at the earliest possible step, and that is at the query. So, to do so, here is the statement...

REPLACE(REPLACE(userEnteredField, CHAR(10), ''), CHAR(13), '')

Since we are not sure if the input is inputing the new line as Carriage Return, Line Feed, or both, you first replace one, then replace the other. Most solutions I see posted have REPLACE(userEnteredField, CHAR(10) + CHAR(13)) which works if they are both present. The way done replaces, one or the other or both.

Thursday, May 6, 2010

I'm always searching for this...

To get the datakey on rowdatabound event for gridviews.


if (e.Row.RowType == DataControlRowType.DataRow)
{
string strY = GridView2.DataKeys[e.Row.RowIndex].Values[1].ToString();
}

The number 1 could be replaced with "KeyName" also.

Sunday, January 31, 2010

Getting Buffalo NFiniti wireless adapter working in linux

Recently, in getting the home dvr setup and working, it needed to be moved into another room. The best solution would be to run cat5 cable to that room, but to do it properly was going to be cumbersome, getting into the attic and running wires is not fun. The easy solution was to get wireless setup on the pc.

I searched and found a reasonably priced wireless-n card on Amazon. It was a Buffalo NFinity Wireless-N USB 2.0 adapter. This will hopefully give me the needed speed when viewing HD content on my PS3 in another room.

Well, the product arrives, and the process of getting installed under Linux began. Unfortunately it did not work "out of the box" so I started searching for what the card really was.... and in the end, it turns out to be a Ralink chipset card, and uses the RT3070USB drivers. They are downloadable from their website. This was like 3 or 4 hour search.

But the fun did not end there. Come to find out, the card may or may not have its "id" in the files provided from Ralink, so I had to modify the source to get it to work. Finally, after that, it worked like a charm.

Here are the steps I took to get this card working in Myth/Ubuntu 9.10...

1. Obtain drivers from Ralink (Ralink Driver Site).
2. Download the RT3070USB(RT307x) driver. In my case it was 2009_1110_RT3070_Linux_STA_v2.1.2.0.tar.bz2
3. Uncompress the resulting file with tar -xvzf 2009_1110_RT3070_Linux_STA_v2.1.2.0.tar (change as needed for the most current driver)
4. CD to the directory created
5. CD to the os/linux directory
6. Open the config.mk file in your favorite editor
7. In the config.mx file, change the HAS_WPA_SUPPLICANT=n and the HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n lines to have =y on the end instead of =n.
8. Save the file.
9. In a terminal window, type in lsusb. You should get a line that ends in Melco, Inc.
10. Notate the ID for the device, in my case it was 0411:015d
11. Open the usb_main_dev.c in your favorite editor.
12. Search for the id earlier in the form of 0x0411,0x15d.
13. If it is found, you are good to go, else add a line to the end of the list that looks like this.... {USB_DEVICE(0x0411,0x015d)}, /* Baffulo WIFI N USB */ If this line is not present, it will not detect and associate the device to the driver.
14. Save and exit out of your editor.
15. CD back to the main directory.
16. Make the driver, sudo make
17. Install the driver, sudo make install
18. To be on the safe side, at this point I restarted. When the pc came back up, I just used the wireless manager in GNome to setup the network connection.

Some futher issues I ran into was that for whatever reason, traffic was still trying to go out the eth0 and not the new wireless connection. I had to edit my /etc/network/interfaces file and comment out the auto eth0 line. At this point, when the pc starts, the wireless connects and works just fine. There were some other things that were specific to my setup with MythTV, but I'll leave those out unless someone asks.

Hopefully this helps someone.

Tuesday, January 26, 2010

Showing gridview when no records present

Here is an easy solution to get a GridView to show headers when there are no records to show.

Code snippet:

DataTable dt = getResults(); //getResults would query your datasource and return a datatable

if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.Databind();
}
else //part that generates the Gridview with headers only
{
dt.Rows.Add(); //adds blank row to table
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Rows[0].Visible = false; //makes blank row invisible
GridView1.Rows[0].Controls.Clear(); //removes any controls for row
}