Click here to Skip to main content
15,915,827 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to retrieve data from d.b by click event on a dynamic picture.. Pin
Eddy Vluggen14-Dec-15 6:20
professionalEddy Vluggen14-Dec-15 6:20 
Questionhow to open crystal report files without installing it Pin
Member 1157949012-Dec-15 14:16
Member 1157949012-Dec-15 14:16 
AnswerRe: how to open crystal report files without installing it Pin
Richard MacCutchan12-Dec-15 21:09
mveRichard MacCutchan12-Dec-15 21:09 
GeneralRe: how to open crystal report files without installing it Pin
Member 1157949016-Dec-15 15:07
Member 1157949016-Dec-15 15:07 
GeneralRe: how to open crystal report files without installing it Pin
Richard MacCutchan16-Dec-15 22:15
mveRichard MacCutchan16-Dec-15 22:15 
QuestionChecking for range of numbers Pin
Eytukan12-Dec-15 3:37
Eytukan12-Dec-15 3:37 
AnswerRe: Checking for range of numbers Pin
OriginalGriff12-Dec-15 3:47
mveOriginalGriff12-Dec-15 3:47 
GeneralRe: Checking for range of numbers Pin
Eytukan12-Dec-15 4:02
Eytukan12-Dec-15 4:02 
GeneralRe: Checking for range of numbers Pin
Eytukan12-Dec-15 4:07
Eytukan12-Dec-15 4:07 
GeneralRe: Checking for range of numbers Pin
OriginalGriff12-Dec-15 4:14
mveOriginalGriff12-Dec-15 4:14 
GeneralRe: Checking for range of numbers Pin
Eytukan12-Dec-15 18:10
Eytukan12-Dec-15 18:10 
GeneralRe: Checking for range of numbers Pin
OriginalGriff12-Dec-15 22:53
mveOriginalGriff12-Dec-15 22:53 
AnswerRe: Checking for range of numbers Pin
harold aptroot12-Dec-15 22:41
harold aptroot12-Dec-15 22:41 
GeneralRe: Checking for range of numbers Pin
Eytukan16-Dec-15 4:00
Eytukan16-Dec-15 4:00 
AnswerRe: Checking for range of numbers Pin
Luc Pattyn14-Dec-15 11:07
sitebuilderLuc Pattyn14-Dec-15 11:07 
GeneralRe: Checking for range of numbers Pin
Eytukan16-Dec-15 3:59
Eytukan16-Dec-15 3:59 
QuestionCurrent datagrid row not being selected Pin
Member 1144944710-Dec-15 0:46
Member 1144944710-Dec-15 0:46 
AnswerRe: Current datagrid row not being selected Pin
Richard Deeming10-Dec-15 2:36
mveRichard Deeming10-Dec-15 2:36 
GeneralRe: Current datagrid row not being selected Pin
Member 1144944710-Dec-15 3:49
Member 1144944710-Dec-15 3:49 
GeneralRe: Current datagrid row not being selected Pin
Richard Deeming10-Dec-15 4:18
mveRichard Deeming10-Dec-15 4:18 
GeneralRe: Current datagrid row not being selected Pin
Member 1144944710-Dec-15 5:34
Member 1144944710-Dec-15 5:34 
GeneralRe: Current datagrid row not being selected Pin
Richard Deeming10-Dec-15 5:53
mveRichard Deeming10-Dec-15 5:53 
Try something like this:
C#
var row = grid_lic.CurrentRow;
if (row == null || !row.Selected)
{
    if (grid_lic.SelectedRows.Count == 0)
    {
        MessageBox.Show("Select a row.");
        return;
    }
    
    row = grid_lic.SelectedRows[0];
}

if (string.IsNullOrEmpty(Convert.ToString(row.Cells[1].Value)) 
  || string.IsNullOrEmpty(Convert.ToString(row.Cells[2].Value)) 
  || string.IsNullOrEmpty(Convert.ToString(row.Cells[6].Value)))
{
    MessageBox.Show("Fill the empty cells");
    return;
}

using (OdbcConnection connection = CreateConnection())
using (OdbcCommand command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection))
{
    command.CommandType = CommandType.Text;
    command.Parameters.AddWithValue("@NIF", row.Cells[1].Value);
    command.Parameters.AddWithValue("@Loja", row.Cells[2].Value);
    command.Parameters.AddWithValue("@Bloqueado", checkBox_bloq.Checked);
    command.Parameters.AddWithValue("@DataFim", row.Cells[4].Value);
    command.Parameters.AddWithValue("@lastupdate", row.Cells[5].Value);
    command.Parameters.AddWithValue("@Nome", row.Cells[6].Value);
    
    connection.Open();
    command.ExecuteNonQuery();
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Current datagrid row not being selected Pin
Member 1144944714-Dec-15 6:25
Member 1144944714-Dec-15 6:25 
GeneralRe: Current datagrid row not being selected Pin
Member 1144944714-Dec-15 7:08
Member 1144944714-Dec-15 7:08 
GeneralRe: Current datagrid row not being selected Pin
Eddy Vluggen10-Dec-15 4:43
professionalEddy Vluggen10-Dec-15 4:43 

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.