Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
K

klaydze

@klaydze
About
Posts
62
Topics
23
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Add new listitem in Listview dynamically
    K klaydze

    Hi Guys, I populated my listview in android using ArrayAdapter. Populating my listview is easy BUT I'm having trouble adding new item on it dynamically. Kindly check my code.

    [Activity(Label = "Country List", MainLauncher = true)]
    public class MyListViewActivity : Activity
    {
    List<string> countries = new List<string>();
    ArrayAdapter<string> adapter;
    ListView lvw;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            
            SetContentView(Resource.Layout.ListviewLayout);
            InitCounties();
                                                
            lvw = FindViewById<ListView>(Resource.Id.lvwCountry);
            EditText txtMsg = FindViewById<EditText>(Resource.Id.edit\_text\_out);
            Button btnSend = FindViewById<Button>(Resource.Id.button\_send);
    
            adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, countries);
            lvw.Adapter = adapter;
            lvw.TextFilterEnabled = true;
            lvw.FastScrollEnabled = true;
    
            btnSend.Click += delegate(object sender, EventArgs e)
            {
                addItems(txtMsg.Text);
            };
        }
     }
    

    void InitCounties()
    {
    countries.Add("Philippines");
    countries.Add("USA");
    countries.Add("Hong Kong");
    countries.Add("Singapore");
    countries.Add("Russia");
    countries.Add("Afghanistan");
    countries.Add("Albania");
    countries.Add("Algeria");
    countries.Add("American Samoa");
    countries.Add("Andorra");
    }

    public void addItems(string newItem)
    {
    counties.Add(newItem);
    adapter.NotifyDataSetChanged();
    }

    Actually the newitem will add in the collection but when I break and check the adapter, the property Count does not changed and my listview is still the same. I know I'm missing somewhere in my code but I don't know where exactly it is. BTW, I'm using Visual Studio 2010 (Mono for Android) in my code. Thanks

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    Mobile csharp android visual-studio help learning

  • MySQL
    K klaydze

    Hi Bernhard, Yep, i already did that but no luck. I don't understand why it return only 1 row. The work around that I did was like this.

    DataTable dt = new DataTable();
    MySqlCommand command = new MySqlCommand();
    command.CommandType = CommandType.Text;
    command.CommandText = "SELECT useraccess_privileges.MenuName, user_access.* FROM useraccess_privileges LEFT JOIN user_access ON user_access.UserName=useraccess_privileges.UserName";

    MySqlDataAdapter da = new MySqlDataAdapter(command);
    da.SelectCommand.Connection = conn;
    da.Fill(dt);

    If the above code was applied then it will return the correct row number. I really don't understand why. Thanks

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    Database database mysql sysadmin help question

  • MySQL
    K klaydze

    Hi All, Can someone explain why MySql treat the two sql statement below different? First Query (without inner join)

    MySqlConnection conn = new MySqlConnection("server=localhost;database=db_test;uid=root;password=1234567");
    MySqlCommand dbCommand = new MySqlCommand("select * from useraccess_privileges", conn);
    dbCommand.CommandType = CommandType.Text;
    if (dbConn.DBConnect.State == ConnectionState.Closed)
    dbConn.DBConnect.Open();
    DataTable dtData = new DataTable();
    dtData.Load(dbCommand.ExecuteReader());

    Result: dtData will return 7 row count

    Second Query (with inner join)

    MySqlConnection conn = new MySqlConnection("server=localhost;database=db_test;uid=root;password=1234567");
    MySqlCommand dbCommand = new MySqlCommand("select t1.*, t2.MenuName from user_access t1 inner join useraccess_privileges t2 on t1.UserName = t2.UserName", conn);
    dbCommand.CommandType = CommandType.Text;
    if (dbConn.DBConnect.State == ConnectionState.Closed)
    dbConn.DBConnect.Open();
    DataTable dtData = new DataTable();
    dtData.Load(dbCommand.ExecuteReader());

    Result: dtData will return 1 row count

    Second query should return 7 rows also since i just reference it to other table to get the full name of the specific username. Thanks

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    Database database mysql sysadmin help question

  • Ajax PopupControlExtender in GridView
    K klaydze

    Hi Ali, I already sent the code. Thanks for the help. Cheers!

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    ASP.NET help question design

  • Ajax PopupControlExtender in GridView
    K klaydze

    Hi, Thanks for the reply. Can you provide a little code on that? Because i don't know how

    Commit

    will affect the refreshing of GridView control. If I'm not mistaken

    Commit

    have one parameter that accept string type. Thanks for providing a little code. :) Thanks

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    ASP.NET help question design

  • Ajax PopupControlExtender in GridView
    K klaydze

    Hi All, I just want to get your opinion on what is the best approach in my gridview.

    Sample Gridview Data.

    | | UserID | First Name | Last Name | Last Loggedin|

    |imgBtn | PHUserId1 | Jim | Carey | 1/16/2011 6:00AM |


    |imgBtn | PHUserId2 | Andres | Boni | 1/27/2011 5:56 PM |


    |imgBtn | PHUserId3 | George | Jungle | 1/2/2011 4:01 AM |

    What i want to do is, in the 1st column of the GridView(grdUserList) control once i click the ImageButton control inside ItemTemplate of the gridview a popup(Ajax PopupExtender) will appear. The popup contains GridView (grdHistory) control inside of it which are the logged history of the user you select. Actually, the design and the output is already done. I get a popup everytime i click the ImageButton on the 1st column of the GridView(grdUserList) control. But the problem now is, how do i refresh the GridView(grdHistory) control in my popup everytime i select different user in my GridView(grdUserlist). I place Click event on the ImageButton but it fires only once. The next click on the ImageButton will no longer fires the Click event. I dont what to used the Ajax ModalPopupExtender for the reason of, i dont what the user to close a popup evertime they click the ImageButton in the 1st row. Thanks in advance

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    ASP.NET help question design

  • DatePicker using JQuery
    K klaydze

    Hi bVagadishnu, You help me alot. Works perfectly!!! Thanks

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    ASP.NET javascript help css design sysadmin

  • DatePicker using JQuery
    K klaydze

    Hi, Im using datepicker using standalone jquery. The datepicker works perfectly in WebForm. Now i decided to use a site master on my sample project and I add some web content form also inside the site.master. In my web content form i add search function with date range. Now, the problem was, after using web content form, datepicker no longer showing the icon "..." beside my asp:textbox. Please see below tags in my site.Master page.

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
    <asp:ScriptReference Path="~/scripts/datepickerjs/jquery-1.3.1.min.js" />
    <asp:ScriptReference Path="~/scripts/datepickerjs/jquery-ui-1.7.1.custom.min.js" />
    <asp:ScriptReference Path="~/scripts/datepickerjs/daterangepicker.jQuery.js" />
    </Scripts>
    </asp:ScriptManager>

    i also place the css in site.master inside the head tag.

    <link rel="Stylesheet" type="text/css" href="style/datepickercss/ui.daterangepicker.css" />
    <link rel="Stylesheet" type="text/css" href="style/datepickercss/redmond/jquery-ui-1.7.1.custom.css" title="ui-theme" />

    In my web content form i place the script after the asp:Content tag.

    <script type="text/jscript">
        $(function() {
            $("#txtDateFrom").datepicker({
                changeMonth: true,
                changeYear: true,
                buttonText: 'Select Date From',
                buttonImage: 'images/calendar.gif',
                buttonImageOnly: true,
                showOn: 'button'
            });
        });
        
        $(function() {
            $("#txtDateTo").datepicker({
                changeMonth: true,
                changeYear: true,
                buttonText: 'Select Date To',
                buttonImage: 'images/calendar.gif',
                buttonImageOnly: true,
                showOn: 'button'
            });
        }); 
    </script>
    

    Finally, when i run my project the "..." is not showing. Normally, when i used web form this "..." will show and i can select a date, but now after switching to web content form, "..." is no longer visible. Thanks

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    ASP.NET javascript help css design sysadmin

  • Populate Listview using LINQ
    K klaydze

    thanks for the link. maybe ill try it later. cheers!

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    C# database help question csharp sql-server

  • Populate Listview using LINQ
    K klaydze

    Hi, I'm trying to populate a listview control and my query is LINQ. I used one of the table (Production.Product) of AdventureWorks database. At first i have problem populating the header, but i figured it out after an hour. The code below is the code on how to populate column in listview using LINQ. Code:

    //Sample result when you query using SQL Server.

    ProductID Name ProductNumber MakeFlag FinishedGoodsFlag Color

    317 LL Crankarm CA-5965 0 1 Black
    318 ML Crankarm CA-5938 0 1 Black
    319 HL Crankarm CA-5990 0 1 Black
    320 Chainring CA-5932 0 1 Black

    //lvw = ListView control

    DataClasses1DataContext db = new DataClasses1DataContext();

    DataTable dt = new DataTable();
    DataColumn dc = new DataColumn();
    DataRow dr;

    var products = from p in db.Products
    where p.Color != null
    select p;

    #region getHeader
    var headers = products.First();
    foreach (var columnHeader in headers.GetType().GetProperties())
    {
    lvw.Columns.Add(columnHeader.Name);
    }
    #endregion

    Now, my problem is how do i populate the result of my query and add it to listview. Actually, i can populate it like this,

    ListViewItem lstItem = null;

    foreach (var itms in products)
    {
    lstItem = new ListViewItem(itms.ProductID.ToString());
    lstItem.SubItems.Add(itms.Name);
    lstItem.SubItems.Add(itms.ProductNumber);
    ..... and so on
    }

    The problem on the above code is that, what if i have a 25 columns in my query result? I have to type in my code 25x the lstItem.SubItems.Add(value) which kinda hassle for me. I want my function in populating the listview to be dynamic. :) Anyone out there can help me to solve my "simple (i think)" problem. Thanks and regards Jessie

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    C# database help question csharp sql-server

  • Variant in VB to C#
    K klaydze

    Hi Simon, Thanks for giving sample program. I'll try this one. By the way, Can you look at the code below. That is my clsConnection where i execute my queries. Is it safe? And can you point out in my code if there is something bad code. This is the way i used it. E.g.

    clsConnection myConn = new clsConnection();
    DataTable DT = new DataTable();
    
    string SQL = "SELECT \* FROM tblUsers";
    DT = myConn.ExecuteQuery(SQL);
    

    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.Text;
    using System.Data.SqlClient;
    using System.Collections;
    using System.Windows.Forms;

    namespace Micromix.Class
    {
    class clsConnection
    {
    public SqlConnection objConnection;
    SqlTransaction objTransaction;

        public bool SqlConnect()
        {
    
            try
            {
                objConnection = new SqlConnection();
                objConnection.ConnectionString = Connect.ConnString.ToString();
                //objConnection.ConnectionString = "Persist Security Info=False;User ID=sa;Initial Catalog=MICROMIX\_PP;Data Source=(local)";
                //objConnection.ConnectionString = "Server=" + GetServer("\\\\conn.cfg") + "; DataBase=" + GetDatabase("\\\\conn.cfg") + "; User ID =" + GetUser("\\\\conn.cfg") + "; Integrated Security=false";
    
                if (objConnection.State == ConnectionState.Closed)
                    objConnection.Open();
    
                return true;
            }
    
            catch (Exception ex)
            {
                MessageBox.Show("Failed to connect to data source.", "Connect Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                MessageBox.Show(ex.Message);
                return false;
            }
    
            finally
            {
                objConnection.Close();
    
            }
    
        }
    
        public DataTable ExecuteQuery(string strSQL)
        {
            DataTable objDataTable;
            SqlDataAdapter objDataAdapter;
    
            try
            {
    
                SqlConnect();
                objDataAdapter = new SqlDataAdapter();
    
                {
    
                    objDataTable = new DataTable();
                    objDataAdapter.SelectCommand = new SqlCommand(strSQL, objConnection, objTransaction);
                    objDataAdapter.Fill(objDataTable);
    
                    return objDataTable;
                }
    
            }
    
            catch (Exception sqlex)
            {
    
    C# csharp database help

  • Variant in VB to C#
    K klaydze

    Simon Stevens wrote:

    But you should be using parametrized queries not just build up the sql statement on your own out of strings.

    Hi Simon, Sorry but I don't get it. "-( Regards klaydze

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    C# csharp database help

  • Variant in VB to C#
    K klaydze

    Simon Stevens wrote:

    It's unmaintainable and insecure code. What if some nasty user comes along and calls GetData("DROP DATABASE [yourdatabase]") And this is just a minor problem. If you expose the ability to execute arbitrary SQL against your database you can wave goodbye to any serious form of security or data integrity. If your just writing a prototype or for fun, don't worry about it too much. Just be aware the code is dangerous and should never grow into production code. If this is production code I would advise a serious rethink about your architecture. You should create a separate data access layer. The DA layer should have strongly typed accessor methods, and they should being using pre written parametrized queries or stored procedures (Google those terms, it's pretty easy to use either with ADO.net) E.g. you would have a UserDA class with a public User GetUser(String userName) method. The method would run the parametrized query and create a User object to be returned to the caller. This prevents a lot of issues. 1) You are only passing in the user name, not the whole SQL string so the caller can't execute whatever SQL they want. 2) You are returning a strongly typed User object so the caller gets exactly what they are expecting. 3) The use of stored procs or parametrized queries prevents SQL injection attacks. 4) You can build in security if you want and only allow certain users to retrieve and modify certain data.

    Hi Simon, Thanks for the advise. In short don't passed a sql statement in a parameter method? How about if I want to create a method that is accessible in all my form the same with my previous code.

    public object GetData(string SQL)

    . How do I secured it? In your example public User GetUser(string sUser), your just passing a single field where "sUser" is my filter in my sql statement inside the User Method.

    SELECT * FROM tblUsers WHERE txtUser = sUser

    Thanks and Regards klaydze

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    C# csharp database help

  • Convert Variant in VB to C#
    K klaydze

    Le Centriste wrote:

    Do you even know C#?

    Yeah but not that good as in VB6.

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    C# csharp database help

  • Variant in VB to C#
    K klaydze

    Simon Stevens wrote:

    A variant in VB is something that can be any type. The closest equivalent in C# is an 'Object'. In C# all data types derive from Object, so you can return the value as an Object and then cast it to what ever type it actually is. (By the way, this is rather bad programming style, you should really be using parametrized queries, or stored procedures. This code is very vulnerable to SQL injection attacks. Also, by just chucking objects around everywhere you lose a lot of the benefits of strongly typed languages like C# such as compile time type checking. Also you seem to be repeating your select/case block about 3 times with the same code in it each time, it seems like you might have some redundant code here)

    Hi Simon, First, thanks for your reply. I already converted my code to C#.Net. Yeah I used object as equivalent of variant. My code something like this.

    public object GetData(string SQL)
    {
    DataTable DT = new DataTable();

     DT = dbConn.ExecuteQuery(SQL); dbConn is my connection class
    
     if (!String.IsNullOrEmpty(DT.Rows\[0\]\[0\].ToString()))
     {
          switch (DT.Column\[0\].DataType.ToString())
          {
                case "System.ToInt32":
                    //Code
                    return;
                case "System.String":
                    //code
                    return;
          }
     }
    

    }

    Any piece of advise? The code just get the 1 field value in the query. Just thinking this is the best way, the shortest way of getting the 1 value in a query. Example:

    string sName;
    sName = GetData("Select txtFirstname From tblUsers Where intID = 1").ToString();

    Regards, klaydze

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    C# csharp database help

  • Convert Variant in VB to C#
    K klaydze

    Hi, I'm just starting to convert my vb6.0 program to c#.net and I have a function in vb6.0 below: Anyone can help me to translate this in c#.net.

    Public Function GetData(SQL As String) As Variant
    Dim RST As ADODB.Recordset
    Set RST = Conn.Execute(SQL)
    With RST
    If .State = adStateOpen Then
    If Not .EOF Then
    If Not IsNull(RST(0)) Then
    Select Case RST(0).Type
    Case adVarChar
    GetData = Trim(RST(0))
    Case Else
    GetData = RST(0)
    End Select
    Else
    Select Case RST(0).Type
    Case adBoolean
    GetData = False
    Case adVarChar
    GetData = ""
    Case adDouble, adInteger
    GetData = 0
    Case adDate, adDBTimeStamp
    GetData = InvalidDate
    End Select
    End If
    Else
    Select Case RST(0).Type
    Case adBoolean
    GetData = False
    Case adVarChar
    GetData = ""
    Case adDouble, adInteger
    GetData = 0
    Case adDate, adDBTimeStamp
    GetData = InvalidDate
    End Select
    End If
    Else
    Select Case RST(0).Type
    Case adBoolean
    GetData = False
    Case adVarChar
    GetData = ""
    Case adDouble, adInteger
    GetData = 0
    Case adDate, adDBTimeStamp
    GetData = InvalidDate
    End Select
    End If
    End With
    Set RST = Nothing
    End Function

    THANKS AND REGARDS klaydze

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    C# csharp database help

  • Variant in VB to C#
    K klaydze

    Hi, I'm just starting to convert my vb6.0 program to c#.net and I have a function in vb6.0 below: Anyone can help me to translate this in c#.net.

    Public Function GetData(SQL As String) As Variant
    Dim RST As ADODB.Recordset
    Set RST = Conn.Execute(SQL)
    With RST
    If .State = adStateOpen Then
    If Not .EOF Then
    If Not IsNull(RST(0)) Then
    Select Case RST(0).Type
    Case adVarChar
    GetData = Trim(RST(0))
    Case Else
    GetData = RST(0)
    End Select
    Else
    Select Case RST(0).Type
    Case adBoolean
    GetData = False
    Case adVarChar
    GetData = ""
    Case adDouble, adInteger
    GetData = 0
    Case adDate, adDBTimeStamp
    GetData = InvalidDate
    End Select
    End If
    Else
    Select Case RST(0).Type
    Case adBoolean
    GetData = False
    Case adVarChar
    GetData = ""
    Case adDouble, adInteger
    GetData = 0
    Case adDate, adDBTimeStamp
    GetData = InvalidDate
    End Select
    End If
    Else
    Select Case RST(0).Type
    Case adBoolean
    GetData = False
    Case adVarChar
    GetData = ""
    Case adDouble, adInteger
    GetData = 0
    Case adDate, adDBTimeStamp
    GetData = InvalidDate
    End Select
    End If
    End With
    Set RST = Nothing
    End Function

    THANKS AND REGARDS klaydze

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    C# csharp database help

  • Installing SQL Server 2005 Developer Edtion
    K klaydze

    hi, thanks for the reply. My OS is Windows Vista Home Premium Edition. I read many instruction on how to properly install this, i also follow some KB but no one help me to install the SQL. Thanks and Regards.

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    Database help database sql-server com sysadmin

  • Installing SQL Server 2005 Developer Edtion
    K klaydze

    hi, anyone can help me installing SQL Server 2005 Developer Edtion. I have a screenshot of the error after installing the SQL Server 2005. step 11 http://s713.photobucket.com/albums/ww134/vhanjess/?action=view¤t=Step11.jpg[^] Actually, i'm installing this for 1 week now and i don't know how to fixed it. Maybe one of you will help me to fixed this. Thanks and Regards klaydze

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    Database help database sql-server com sysadmin

  • Positioning the image in Excel 2007 [modified]
    K klaydze

    Hi, I create a simple program that can open a image in excel. But there is a problem, I want it to position a little bit lower because I have some data that i want to write above that image. And also how do I re size the image that i put in the excel? Here is my code: Dim xlsApp As New Microsoft.Office.Interop.Excel.Application Dim xlsWSheet As New Microsoft.Office.Interop.Excel.Worksheet Dim excelFiles As String = "c:\Test.xlsx" Dim pic As String = "c:\MsC.bmp" xlsApp.Visible = True xlsApp.Workbooks.Open(excelFiles) xlsApp.ActiveSheet.Pictures.Insert(pic) xlsApp = Nothing GC.Collect() GC.WaitForPendingFinalizers() Anyone change help me how to do the position of image. Thanks Regards, Jessie

    if(you type your code here) { Messagebox.Show("You help me a lot!"); } else { You help me = null; }

    modified on Monday, July 28, 2008 4:55 AM

    Visual Basic help question com tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups