我想在窗体里面做一个表格,要求能从一个.txt文件里面传入数据,也可以自己输入。

解决方案 »

  1.   

    tablelayoutpanel动态生成textbox,并读取txt赋值
      

  2.   

    哈哈  这个我刚刚做过我把全部代码给你,希望楼主个高分哈。
    你说的就是“文件导入”这个例子。如果不太懂的话,添加我的QQ543346734            if (ofdImport.ShowDialog() == DialogResult.OK)
                {
                    using (FileStream fileStream = File.OpenRead(ofdImport.FileName))
                    {
                        using (StreamReader streamRead = new StreamReader(fileStream))
                        {                        using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;
    AttachDbFilename=|Datadirectory|\name_and_age.mdf;
    Integrated Security=True;User Instance=True"))
                            {
                                conn.Open();
                                using (SqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "insert into use4(Name,Age)  values(@Name,@Age)";
                                    string line = null;
                                    while ((line = streamRead.ReadLine()) != null)
                                    {
                                        string[] strs = line.Split('|');
                                        string name = strs[0];
                                        int age = Convert.ToInt32(strs[1]);                                    cmd.Parameters.Clear();                                    cmd.Parameters.Add(new SqlParameter("Name", name));
                                        cmd.Parameters.Add(new SqlParameter("Age", age));
                                        cmd.ExecuteNonQuery();
                                    }
                                }                        }                        MessageBox.Show("导入成功 ");
                      }
                    }
                }
      

  3.   

    跟你说一下啊,我这个是winform程序,不过都一样啦。。
      

  4.   

    使用 DataGridView 控件。它提供了类似 Excel 表格的界面。