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
B

bhumber

@bhumber
About
Posts
4
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Inserting a record into a database with a front web form
    B bhumber

    The code below should insert this record into the database, I don't the error. I drops through and run the line that enables the btnAdd.Enable = true. How do I fix it? private void SaveRecord() { string strSQL; if(btnSave.CommandArgument == "Add") { strSQL = "INSERT INTO CoinCollection " + " (ID, TypeOfCoin, YearOfCoin, StateOfCoin, DateReceive)" + "VALUES " + " (@ID, @TypeOfCoin, @YearOfCoin, @StateOfCoin, @DateReceive)"; } else { // The user is updating an existing item strSQL = "UPDATE CoinCollection " + " SET TypeOfCoin = @TypeOfCoin, " + " YearOfCoin = @YearOfCoin, " + " StateOfCoin = @StateOfCoin, " + " DateReceive = @DateReceive " + "WHERE ID = @ID"; } SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["connString"]); SqlCommand cmSQL = new SqlCommand(strSQL, conn); // Add all the requuired SQL Parmeters. cmSQL.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = Convert.ToInt32(tbID.Text); cmSQL.Parameters.Add(new SqlParameter("@TypeOfCoin", SqlDbType.VarChar, 50)).Value = tbToc.Text; cmSQL.Parameters.Add(new SqlParameter("@YearOfCoin", SqlDbType.VarChar, 50)).Value = tbYoc.Text; cmSQL.Parameters.Add(new SqlParameter("@StateOfCoin", SqlDbType.VarChar, 50)).Value = tbSoc.Text; cmSQL.Parameters.Add(new SqlParameter("@DateReceive", SqlDbType.VarChar, 50)).Value = tbDr.Text; try { conn.Open(); cmSQL.ExecuteNonQuery(); strMsg = "Coin successfully saved to the database."; } catch(Exception exp) { strErrorMsg = "Database error! Coins not saved to database. Error Message: " + exp.Message; } finally { conn.Close(); btnAdd.Enabled = true; } } bhumber

    Database database help question announcement

  • Urgent Help on C#~~
    B bhumber

    Good morning Write a method like the below to populate the form // could be global private string strErrorMsg = "Database error: " + exp.Message; try { SqlConnection conn = new SqlConnection(put your connection string hear); strSQL = "SELECT * FROM theNameOftheTable"; SqlCommand cmd = new SqlCommand(strSQL, conn); cmd.CommandType = CommandType.Text; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); // a method to display the information, is this a grid or form with textboxes? conn.Close(); cmd.Dispose(); conn.Dispose(); } catch { //some message about the error strErrorMsg; }

    Web Development help question csharp database tutorial

  • add/save a row to a db C#
    B bhumber

    Good morning and thanks for looking at this for me. The answer to your question is "no" the program drops through the exceptions to the finally block and executes the code to enable the Add button. Brent

    Web Development database question csharp help announcement

  • add/save a row to a db C#
    B bhumber

    How do you add/save a row using the INSERT sql command in a web form with textbox not a datagrid? Below is my code, what wroung and why does fall through to the "finally block?" private void SaveRecord() { string strSQL; if(btnSave.CommandArgument == "Add") { strSQL = "INSERT INTO CoinCollection " + " (ID, TypeOfCoin, YearOfCoin, StateOfCoin, DateReceive)" + "VALUES " + " (@ID, @TypeOfCoin, @YearOfCoin, @StateOfCoin, @DateReceive)"; } else { // The user is updating an existing item strSQL = "UPDATE CoinCollection " + " SET TypeOfCoin = @TypeOfCoin, " + " YearOfCoin = @YearOfCoin, " + " StateOfCoin = @StateOfCoin, " + " DateReceive = @DateReceive " + "WHERE ID = @ID"; } SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["connString"]); SqlCommand cmSQL = new SqlCommand(strSQL, conn); // Add all the requuired SQL Parmeters. cmSQL.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = Convert.ToInt32(tbID.Text); cmSQL.Parameters.Add(new SqlParameter("@TypeOfCoin", SqlDbType.VarChar, 50)).Value = tbToc.Text; cmSQL.Parameters.Add(new SqlParameter("@YearOfCoin", SqlDbType.VarChar, 50)).Value = tbYoc.Text; cmSQL.Parameters.Add(new SqlParameter("@StateOfCoin", SqlDbType.VarChar, 50)).Value = tbSoc.Text; cmSQL.Parameters.Add(new SqlParameter("@DateReceive", SqlDbType.VarChar, 50)).Value = tbDr.Text; try { conn.Open(); cmSQL.ExecuteNonQuery(); strMsg = "Coin successfully saved to the database."; } catch(Exception exp) { strErrorMsg = "Database error! Coins not saved to database. Error Message: " + exp.Message; } finally { conn.Close(); btnAdd.Enabled = true; } }

    Web Development database question csharp help announcement
  • Login

  • Don't have an account? Register

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