Click here to Skip to main content
15,898,134 members
Home / Discussions / C#
   

C#

 
AnswerRe: Connecting database from different domain Pin
Dave Kreskowiak24-Oct-11 4:06
mveDave Kreskowiak24-Oct-11 4:06 
Questioncrystal report Pin
Aisha sharma24-Oct-11 0:50
Aisha sharma24-Oct-11 0:50 
AnswerRe: crystal report Pin
Richard MacCutchan24-Oct-11 1:17
mveRichard MacCutchan24-Oct-11 1:17 
QuestionCreating CAPTCHA using SQL Database in ASP.NET Pin
M Gxabana23-Oct-11 8:36
M Gxabana23-Oct-11 8:36 
AnswerRe: Creating CAPTCHA using SQL Database in ASP.NET Pin
OriginalGriff23-Oct-11 21:57
mveOriginalGriff23-Oct-11 21:57 
GeneralRe: Creating CAPTCHA using SQL Database in ASP.NET Pin
Mycroft Holmes23-Oct-11 22:16
professionalMycroft Holmes23-Oct-11 22:16 
GeneralRe: Creating CAPTCHA using SQL Database in ASP.NET Pin
OriginalGriff23-Oct-11 22:35
mveOriginalGriff23-Oct-11 22:35 
QuestionNewly added rows from Datagrid Pin
SFORavi22-Oct-11 13:05
SFORavi22-Oct-11 13:05 
Hi
For my assignment, I need to find out all rows that were newly added into the datagrid and add it to the database.

I have pasted my code below, getting error in setting dRow where it says index is out of range.. I thought the newly added row can be accessed thru the index. Please let me know how to access the cells in newly added row.

public partial class AllCustomer : Form
    {
        private int ii;
        public AllCustomer()
        {
            InitializeComponent();

            string strConnection = "Data Source=.;Initial Catalog=Company;Integrated Security=True";

            SqlConnection sqlconn = new SqlConnection(strConnection);
            DataSet ds = new DataSet();
            string sqls = "select * from CustomerMaster";

            SqlDataAdapter da = new SqlDataAdapter(sqls, sqlconn);

            sqlconn.Open();
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
            ii = dataGridView1.RowCount;
            sqlconn.Close();

        }

       private void btn_Add_Click(object sender, EventArgs e)
        {
            string strConnection = "Data Source=.;Initial Catalog=Company;Integrated Security=True";

            SqlConnection sqlconn = new SqlConnection(strConnection);
            DataSet ds = new DataSet();
            string sqls = "select * from CustomerMaster";

            SqlDataAdapter da = new SqlDataAdapter(sqls, sqlconn);
            SqlCommandBuilder cmdBldr = new SqlCommandBuilder(da);

            sqlconn.Open();
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];

            for (int j = ii; j >= dataGridView1.RowCount; j++)
            {


                DataRow dRow = ds.Tables[0].NewRow();
                
                dRow["cust_name"] = dataGridView1.Rows[j].Cells["cust_name"].Value.ToString();
                dRow["cust_st_addr"] = dataGridView1.Rows[j].Cells["cust_st_addr"].Value.ToString(); 
                dRow["cust_city_state_zip"] = dataGridView1.Rows[j].Cells["cust_city_state_zip"].Value.ToString(); 
                dRow["cust_phone"] = dataGridView1.Rows[j].Cells["cust_phone"].Value.ToString(); 
                dRow["cust_stat_cd"] = dataGridView1.Rows[j].Cells["cust_stat_cd"].Value.ToString(); 

                //datetime hard coded for test only...
                dRow["cust_add_dt"] = "2011-10-14";
                dRow["cust_updt_dt"] = "2011-10-15";



                ds.Tables[0].Rows.Add(dRow);
            }
            da.Update(ds.Tables[0]);
        }

        

        
    }

AnswerRe: Newly added rows from Datagrid Pin
Dan Mos23-Oct-11 3:02
Dan Mos23-Oct-11 3:02 
Question8086 assembler Pin
gif202022-Oct-11 11:09
gif202022-Oct-11 11:09 
AnswerRe: 8086 assembler Pin
Dave Kreskowiak22-Oct-11 11:36
mveDave Kreskowiak22-Oct-11 11:36 
AnswerRe: 8086 assembler Pin
Luc Pattyn22-Oct-11 13:22
sitebuilderLuc Pattyn22-Oct-11 13:22 
GeneralRe: 8086 assembler Pin
Paul Conrad23-Oct-11 9:16
professionalPaul Conrad23-Oct-11 9:16 
AnswerRe: 8086 assembler Pin
Luc Pattyn23-Oct-11 9:42
sitebuilderLuc Pattyn23-Oct-11 9:42 
GeneralRe: 8086 assembler Pin
Paul Conrad23-Oct-11 9:55
professionalPaul Conrad23-Oct-11 9:55 
Questionconvert unicode to iransystem Pin
mersad0022-Oct-11 6:33
mersad0022-Oct-11 6:33 
AnswerRe: convert unicode to iransystem Pin
BobJanova23-Oct-11 22:29
BobJanova23-Oct-11 22:29 
AnswerRe: convert unicode to iransystem Pin
Pascal Ganaye23-Oct-11 23:05
Pascal Ganaye23-Oct-11 23:05 
AnswerRe: convert unicode to iransystem Pin
Keith Barrow24-Oct-11 1:53
professionalKeith Barrow24-Oct-11 1:53 
QuestionAnimation format Pin
Aleonis22-Oct-11 5:59
Aleonis22-Oct-11 5:59 
QuestionDoes anyone know how to unbox or convert a "1" as a nullable long? Pin
Alaric_22-Oct-11 5:37
professionalAlaric_22-Oct-11 5:37 
AnswerRe: Does anyone know how to unbox or convert a "1" as a nullable long? Pin
Alaric_22-Oct-11 6:03
professionalAlaric_22-Oct-11 6:03 
GeneralRe: Does anyone know how to unbox or convert a "1" as a nullable long? Pin
Alaric_22-Oct-11 6:04
professionalAlaric_22-Oct-11 6:04 
QuestionScope issue declaring a delegate within a static class Pin
dotman121-Oct-11 23:15
dotman121-Oct-11 23:15 
AnswerRe: Scope issue declaring a delegate within a static class Pin
dotman121-Oct-11 23:33
dotman121-Oct-11 23:33 

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.