Click here to Skip to main content
15,888,590 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# ECG Analysis Algorithm Pin
Gerry Schmitz11-Dec-15 7:14
mveGerry Schmitz11-Dec-15 7:14 
GeneralHow I Can Make My Program With Multiple Language For Forms In C# ? Pin
eng_aza9-Dec-15 15:07
eng_aza9-Dec-15 15:07 
GeneralRe: How I Can Make My Program With Multiple Language For Forms In C# ? Pin
Mycroft Holmes9-Dec-15 19:03
professionalMycroft Holmes9-Dec-15 19:03 
GeneralRe: How I Can Make My Program With Multiple Language For Forms In C# ? Pin
Gerry Schmitz11-Dec-15 7:15
mveGerry Schmitz11-Dec-15 7:15 
QuestionSolid color image vs Panel with BackColor Pin
David Sattler9-Dec-15 5:34
David Sattler9-Dec-15 5:34 
AnswerRe: Solid color image vs Panel with BackColor Pin
OriginalGriff9-Dec-15 5:48
mveOriginalGriff9-Dec-15 5:48 
GeneralRe: Solid color image vs Panel with BackColor Pin
David Sattler9-Dec-15 5:52
David Sattler9-Dec-15 5:52 
Questionhow to fill the cells of a DataGridView directly Pin
Member 114494479-Dec-15 1:49
Member 114494479-Dec-15 1:49 

How to fill directly the cells of a datagrid linked to a table in a databasis? I tried this code but no data is added to the table. It only works when the data comes from a textbox and then sent to the datagrid cells :

C#
public void BD_Conexao()
    {
        try
        {
            OdbcConnection con = new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=xxxxx; database=lic; uid=es; password=1234; option = 3 ");
            con.Open();
        }

        catch (Exception ex)
        {
            Console.WriteLine("Erro na ligação à base de dados. \n{0}", ex.Message);
            return;
        }

    }
public void Consulta()
    {
        con = new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=xxx; database=lice; uid=estagio; password=1234; option = 3 ");
        con.Open();

        OdbcCommand Command = con.CreateCommand();
        Command.CommandText = "select lojas.Id, lojas.NIF, lojas.Loja, lojas.Bloqueado, lojas.DataFim, lojas.lastupdate, lojas.Nome";


        Command.CommandType = CommandType.Text;
        Command.Connection = con;

        OdbcDataAdapter adapter = new OdbcDataAdapter();
        adapter.SelectCommand = Command;

        DataSet dataSet = new DataSet();
        adapter.Fill(dataSet);

        grid_lic.DataSource = dataSet;

        grid_lic.DataMember = dataSet.Tables[0].TableName;
      }

 private void bt_preencher_Click(object sender, EventArgs e)
 {
   BD_Conexao();

   string DataFim = dateTimePicker.Value.ToString("yyyy-MM-dd");
   string lastupdate = dateTimePicker2.Value.ToString("yyyy-MM-dd");
   Commandtext = "insert into lojas (NIF,Loja,bloqueado, DataFim, lastupdate, Nome) values (@NIF,@Loja,@Bloqueado,@DataFim,@lastupdate,@Nome)";

   OdbcCommand Command = new OdbcCommand(Commandtext, con);

   Command.CommandType = CommandType.Text;

   Command.Parameters.AddWithValue("@NIF", grid_lic.CurrentRow.Cells[1].Value);
   Command.Parameters.AddWithValue("@Loja", grid_lic.CurrentRow.Cells[2].Value);
   Command.Parameters.AddWithValue("@Bloqueado", checkBox_bloq.Checked);
   Command.Parameters.AddWithValue("@DataFim", grid_lic.CurrentRow.Cells[4].Value);
   Command.Parameters.AddWithValue("@lastupdate", grid_lic.CurrentRow.Cells[5].Value);
   Command.Parameters.AddWithValue("@Nome", grid_lic.CurrentRow.Cells[6].Value);

   Command.ExecuteNonQuery();
   Consulta();
}


modified 9-Dec-15 10:09am.

AnswerRe: how to fill the cells of a DataGridView directly Pin
Richard MacCutchan9-Dec-15 2:37
mveRichard MacCutchan9-Dec-15 2:37 
GeneralRe: how to fill the cells of a DataGridView directly Pin
Member 114494479-Dec-15 3:58
Member 114494479-Dec-15 3:58 
GeneralRe: how to fill the cells of a DataGridView directly Pin
Richard Deeming9-Dec-15 4:02
mveRichard Deeming9-Dec-15 4:02 
GeneralRe: how to fill the cells of a DataGridView directly Pin
Member 114494479-Dec-15 4:30
Member 114494479-Dec-15 4:30 
GeneralRe: how to fill the cells of a DataGridView directly Pin
Richard Deeming9-Dec-15 4:44
mveRichard Deeming9-Dec-15 4:44 
GeneralRe: how to fill the cells of a DataGridView directly Pin
Member 114494479-Dec-15 6:37
Member 114494479-Dec-15 6:37 
QuestionChild Window Form does not show color scheme on gridview Pin
Member 121312778-Dec-15 23:39
Member 121312778-Dec-15 23:39 
SuggestionRe: Child Window Form does not show color scheme on gridview Pin
Richard MacCutchan9-Dec-15 0:13
mveRichard MacCutchan9-Dec-15 0:13 
Questionc# for android Pin
eng_aza8-Dec-15 14:03
eng_aza8-Dec-15 14:03 
AnswerRe: c# for android Pin
Dave Kreskowiak8-Dec-15 15:27
mveDave Kreskowiak8-Dec-15 15:27 
AnswerRe: c# for android Pin
BillWoodruff8-Dec-15 16:14
professionalBillWoodruff8-Dec-15 16:14 
AnswerRe: c# for android Pin
Hari-CodeBlogger11-Dec-15 23:44
Hari-CodeBlogger11-Dec-15 23:44 
QuestionTransfer data from Dataset to Report Viewer Pin
PDTUM8-Dec-15 8:32
PDTUM8-Dec-15 8:32 
AnswerRe: Transfer data from Dataset to Report Viewer Pin
Gerry Schmitz8-Dec-15 12:29
mveGerry Schmitz8-Dec-15 12:29 
GeneralRe: Transfer data from Dataset to Report Viewer Pin
PDTUM8-Dec-15 12:53
PDTUM8-Dec-15 12:53 
GeneralRe: Transfer data from Dataset to Report Viewer Pin
Gerry Schmitz8-Dec-15 13:29
mveGerry Schmitz8-Dec-15 13:29 
GeneralRe: Transfer data from Dataset to Report Viewer Pin
PDTUM8-Dec-15 14:14
PDTUM8-Dec-15 14:14 

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.