how to update columes in the mysql using C#.net

Last post 09-05-2008 12:43 PM by Karrar666. 4 replies.

Sort Posts:

  • how to update columes in the mysql using C#.net

    08-29-2008, 9:36 AM

     Hi,

    in my application I have update the columes . But that is in mysql databse.

    I tried with normal sql query. 

     

    Is it same as sql server 2005 or is their any diiff.

    please help me.

     

    very urgent

     

     

  • Re: how to update columes in the mysql using C#.net

    08-29-2008, 9:41 AM
    • All-Star
      20,949 point All-Star
    • bullpit
    • Member since 06-29-2006, 3:59 PM
    • Posts 4,631

    It should be same. What have you tried?

  • Re: how to update columes in the mysql using C#.net

    08-29-2008, 9:59 AM

    I tried with this

    string un = (string)Session["username"];

    string str1 = @"update tbl_users set seeking=" + ddlseek.Text +" ,agefrom=" + ddlfrom.Text + ",ageto=" + ddlto.Text +"where username=";

    string str2 = "'" + un + "'";

    string str = str1 + str2;

    MySqlCommand cmd = new MySqlCommand(str, conn);

    conn.Open();

    cmd.ExecuteNonQuery();

    conn.Close();

     Error Message:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'username='user1'' at line 1

     

    But with the same srting I tried with the mysqlcmd, It's working.

     

    please help me.

     

    thank you

  • Re: how to update columes in the mysql using C#.net

    08-29-2008, 10:16 AM
    • All-Star
      20,949 point All-Star
    • bullpit
    • Member since 06-29-2006, 3:59 PM
    • Posts 4,631

    krishnakumari:

    +"where username=";

    You don't have a space before "where". Insert a space like this: " where "

  • Re: how to update columes in the mysql using C#.net

    09-05-2008, 12:43 PM
    • Member
      30 point Member
    • Karrar666
    • Member since 08-31-2008, 8:39 AM
    • IRAQ
    • Posts 10

    MySqlParameter usernameParameter = new MySqlParameter("?username", MySqlDbType.VarChar, 150); // You can use string patameter

    usernameParameter.Value = string (string)Session["username"];

    cmd.Parameter.Add(usernameParameter);

    MySqlParameter seekingParameter = new MySqlParameter("?seeking", MySqlDbType.Int32, 0); // You can use Integer Patameter

    seekingParameter.Value = ddlseek.Text;

    cmd.Parameter.Add(seekingParameter);

    MySqlParameter agefromParameter = new MySqlParameter("?agefrom", MySqlDbType.Date, 0); // You can use date Patameter

    agefromParameter.Value = ddlfrom.Text;

    cmd.Parameter.Add(agefromParameter);

    string SQL = " UPDATE tbl_users SET seeking = ?seeking, agefrom = ?agefrom Where username = ?username";MySqlCommand cmd = new MySqlCommand(SQL, conn);

    conn.Open();

    cmd.ExecuteNonQuery();

    conn.Close();

     

    Always use Paramters Coz is protected against SQL injection and easy to debug ;)

Page 1 of 1 (5 items)