Click here to Skip to main content
15,911,646 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: how to run outlook on client Pin
fjdiewornncalwe13-Oct-10 3:42
professionalfjdiewornncalwe13-Oct-10 3:42 
GeneralRe: how to run outlook on client Pin
magichi13-Oct-10 16:56
magichi13-Oct-10 16:56 
GeneralRe: how to run outlook on client Pin
fjdiewornncalwe14-Oct-10 13:15
professionalfjdiewornncalwe14-Oct-10 13:15 
QuestionUpdate all gridview rows at once Pin
amina8912-Oct-10 1:47
amina8912-Oct-10 1:47 
AnswerRe: Update all gridview rows at once Pin
Geoff Williams12-Oct-10 3:06
Geoff Williams12-Oct-10 3:06 
GeneralRe: Update all gridview rows at once Pin
phil.o12-Oct-10 4:23
professionalphil.o12-Oct-10 4:23 
GeneralRe: Update all gridview rows at once [modified] Pin
amina8914-Oct-10 0:02
amina8914-Oct-10 0:02 
GeneralRe: Update all gridview rows at once Pin
phil.o14-Oct-10 5:35
professionalphil.o14-Oct-10 5:35 
Hi,

Try to use the correct types when you assign your parameter : here you define float parameters but you assign them string values.

Try instead :

string cmd = "UPDATE EXAMEN SET NOTE = (CASE WHEN CODE_MATIERE = '111' then @note1 WHEN CODE_MATIERE = '112' then @note2 END) WHERE NUM_INSCRIPTION = @num;";
float note1, note2;
string num;
SqlCommand myCommand;
SqlParameter param1, param2, param3;

using (SqlConnection myConnection = new SqlConnection(ConnectionString))
{
   myConnection.Open();

   foreach (GridViewRow row in GridView1.Rows)
   {
      note1 = float.Parse(((TextBox)row.FindControl("note1")).Text);
      note2 = float.Parse(((TextBox)row.FindControl("note2")).Text);
      num = ((Label)row.FindControl("lblUserID1")).Text;

      myCommand = new SqlCommand(cmd, myConnection);

      param1 = new SqlParameter("num", SqlDbType.VarChar, 4);
      param1.Value = num;
      myCommand.Parameters.Add(param1);

      param2 = new SqlParameter("note1", SqlDbType.Float, 2);
      param2.Value = note1;
      myCommand.Parameters.Add(param2);

      param3 = new SqlParameter("note2", SqlDbType.Float, 2);
      param3.Value = note2;
      myCommand.Parameters.Add(param3);

      myCommand.ExecuteNonQuery();
   }

   myConnection.Close();
}


Several points here :
- Try to obtain your values in the type you will need them in your database (note1, note2, num).
- I removed the concatenations in the query string for higher simplicity.
- When you define your parameters, defines variables of type SqlParameter (as in my previous example) ; it will exhaust you from having to find them out using an array accessor.
- The '@' sign for parameters must only be present in the SQL query string, not in the declaration of the SqlParameter objects.
- It's better to open your connection before the loop, and close it after ; opening connection is time-consuming, and you'd better avoid it if you can. And, as SqlConnection implements IDisposable interface, it's even better to use it with an 'using' statement (which will take care of disposing the connection when not needed anymore).

If this still doesn't work, start a debug session and watch for the content of all your variables, you should see there what's the issue.

Hope it'll help Wink | ;)
GeneralRe: Update all gridview rows at once Pin
amina8917-Oct-10 3:35
amina8917-Oct-10 3:35 
GeneralRe: Update all gridview rows at once Pin
amina8921-Oct-10 0:04
amina8921-Oct-10 0:04 
GeneralRe: Update all gridview rows at once Pin
amina8922-Oct-10 15:24
amina8922-Oct-10 15:24 
QuestionPanel Control Pin
Thanusree Duth11-Oct-10 20:58
Thanusree Duth11-Oct-10 20:58 
AnswerRe: Panel Control Pin
Brij11-Oct-10 22:05
mentorBrij11-Oct-10 22:05 
AnswerRe: Panel Control Pin
Tej Aj12-Oct-10 21:35
Tej Aj12-Oct-10 21:35 
QuestionAUTOCOMPLETE Pin
padmanabhan N11-Oct-10 20:37
padmanabhan N11-Oct-10 20:37 
AnswerRe: AUTOCOMPLETE Pin
Pete O'Hanlon11-Oct-10 23:57
mvePete O'Hanlon11-Oct-10 23:57 
AnswerRe: AUTOCOMPLETE Pin
Steve Echols13-Oct-10 7:05
Steve Echols13-Oct-10 7:05 
GeneralRe: AUTOCOMPLETE Pin
padmanabhan N14-Oct-10 0:20
padmanabhan N14-Oct-10 0:20 
GeneralRe: AUTOCOMPLETE Pin
Steve Echols14-Oct-10 16:46
Steve Echols14-Oct-10 16:46 
QuestionDataPager with ListView Pin
Łukasz Nowakowski11-Oct-10 3:48
Łukasz Nowakowski11-Oct-10 3:48 
QuestionPrinting question Pin
Abrojus11-Oct-10 2:56
Abrojus11-Oct-10 2:56 
QuestionMerge between VB & C# [modified] Pin
Abdullah S. Abdelhay11-Oct-10 1:53
Abdullah S. Abdelhay11-Oct-10 1:53 
AnswerRe: Merge between VB & C# Pin
Brij11-Oct-10 2:40
mentorBrij11-Oct-10 2:40 
AnswerRe: Merge between VB & C# Pin
Abhijit Jana11-Oct-10 7:59
professionalAbhijit Jana11-Oct-10 7:59 
GeneralRe: Merge between VB & C# [WORKED] Pin
Abdullah S. Abdelhay12-Oct-10 23:59
Abdullah S. Abdelhay12-Oct-10 23:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.