Win Form VS Asp.Net Gridview中的Datagridview [英] Datagridview in Win Form VS Asp.Net Gridview

查看:57
本文介绍了Win Form VS Asp.Net Gridview中的Datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#windows窗体应用程序中,我有以下代码...



In a C# windows form app I had the following code...

using (SqlConnection cs = new SqlConnection(
@"Data Source=100-NUprod-P-001.acds.net;Initial Catalog=Nuprod;Persist Security Info=True;User ID=Nuprod;Password=MyPa$$word"))
            {
                cs.Open();


                using (SqlDataAdapter da = new SqlDataAdapter(@"Select top 25 stationipaddress From machines", cs))
                {
                     3
                     Use DataAdapter to fill DataTable
                    DataTable t = new DataTable();
                    da.Fill(t);

                     4
                     Render data onto the screen
                    dataGridView1.DataSource = t; // <-- From your designer
                }


                Thread.Sleep(2000);



                foreach (DataGridViewRow row in this.dataGridView1.Rows)
                {
                    try
                    {

                        foreach (DataGridViewCell cell in row.Cells)
                        {
                            if (!cell.Size.IsEmpty)
                            {


                                MessageBox.Show(cell.Value.ToString());


                                ProcessStartInfo startInfo = new ProcessStartInfo();
                                startInfo.FileName = "net.exe";
                                startInfo.Arguments = @"use \\" + cell.Value.ToString() + "\\c$" + " " + "Password /user:admin";
                                startInfo.UseShellExecute = false;
                                startInfo.RedirectStandardOutput = true;
                                startInfo.RedirectStandardInput = true;
                                startInfo.CreateNoWindow = true;
                                Process.Start(startInfo);

                                Thread.Sleep(1000);



                            }
                        }
                    }
                    catch (Exception)
                    {

                        MessageBox.Show("First Query Complete");
                        foreach (DataGridViewRow row1 in this.dataGridView1.Rows)
                        {
                            try
                            {

                                foreach (DataGridViewCell cell in row1.Cells)
                                {
                                    if (!cell.Size.IsEmpty)
                                    {

            

                                        int timeout = 5000;

           
                                        Process process = new Process();
                                        process.StartInfo.FileName = "xcopy";
                                        process.StartInfo.Arguments = textBox1.Text + " " + @"\\" + cell.Value.ToString() + @"\" + textBox2.Text + @"/C/Y/E/Q/F";
                                        process.StartInfo.UseShellExecute = false;
                                        process.StartInfo.RedirectStandardOutput = true;
                                        process.StartInfo.RedirectStandardInput = true;
                                        process.StartInfo.CreateNoWindow = true;
                                        process.Start();
                                        process.WaitForExit(timeout);

                                                                         
                                          
                                        
                                        



                                    }
                                }
                            }
                            catch (Exception)
                            {
                                

                                var compiler = new Process();
                                compiler.StartInfo.FileName = "net.exe";
                                compiler.StartInfo.Arguments = "use * /delete /Y";
                                compiler.StartInfo.UseShellExecute = true;
                                compiler.StartInfo.RedirectStandardOutput = false;
                                compiler.Start();

                                Thread.Sleep(1000);

                                MessageBox.Show("Part 1 Copy Done");
                                cs.Close();


                            }



                        }

                    }

                }





然后当我尝试将其放入我的ASP.Net Web App时,我会使用以下代码获得以下错误。



错误1无法找到类型或命名空间名称''GridViewCell'(您是否缺少using指令或程序集引用?)





And then when I try to put it in my ASP.Net Web App I get the following errors with the following code.

Error 1 The type or namespace name ''GridViewCell'' could not be found (are you missing a using directive or an assembly reference?)

  using (SqlConnection cs = new SqlConnection(
@"Data Source=100-NUprod-P-001.acds.net;Initial Catalog=Nuprod;Persist Security Info=True;User ID=Nuprod;Password=MyPa$$word"))
            {
                cs.Open();


                using (SqlDataAdapter da = new SqlDataAdapter(@"Select top 25 stationipaddress From machines", cs))
                {
                     //3
                     //Use DataAdapter to fill DataTable
                    DataTable t = new DataTable();
                    da.Fill(t);

                     //4
                     //Render data onto the screen
                    GridView1.DataSource = t; // <-- From your designer
                }


                Thread.Sleep(2000);



                foreach (GridViewRow row in this.GridView1.Rows)
                {
                    try
                    {

                        foreach (GridViewCell cell in row.Cells)
                        {
                            if (!cell.Size.IsEmpty)
                            {


                                //MessageBox.Show(cell.Value.ToString());


                                ProcessStartInfo startInfo = new ProcessStartInfo();
                                startInfo.FileName = "net.exe";
                                startInfo.Arguments = @"use \\" + cell.Value.ToString() + "\\c$" + " " + "Password /user:admin";
                                startInfo.UseShellExecute = false;
                                startInfo.RedirectStandardOutput = true;
                                startInfo.RedirectStandardInput = true;
                                startInfo.CreateNoWindow = true;
                                Process.Start(startInfo);

                                Thread.Sleep(1000);



                            }
                        }
                    }
                    catch (Exception)
                    {

                        //MessageBox.Show("First Query Complete");
                        foreach (GridViewRow row1 in this.GridView1.Rows)
                        {
                            try
                            {

                                foreach (GridViewCell cell in row1.Cells)
                                {
                                    if (!cell.Size.IsEmpty)
                                    {

            

                                        int timeout = 5000;

           
                                        Process process = new Process();
                                        process.StartInfo.FileName = "xcopy";
                                        process.StartInfo.Arguments = textBox1.Text + " " + @"\\" + cell.Value.ToString() + @"\" + textBox2.Text + @"/C/Y/E/Q/F";
                                        process.StartInfo.UseShellExecute = false;
                                        process.StartInfo.RedirectStandardOutput = true;
                                        process.StartInfo.RedirectStandardInput = true;
                                        process.StartInfo.CreateNoWindow = true;
                                        process.Start();
                                        process.WaitForExit(timeout);

                                                                         
                                          
                                        
                                        



                                    }
                                }
                            }
                            catch (Exception)
                            {
                                

                                var compiler = new Process();
                                compiler.StartInfo.FileName = "net.exe";
                                compiler.StartInfo.Arguments = "use * /delete /Y";
                                compiler.StartInfo.UseShellExecute = true;
                                compiler.StartInfo.RedirectStandardOutput = false;
                                compiler.Start();

                                Thread.Sleep(1000);

                                //MessageBox.Show("Part 1 Copy Done");
                                cs.Close();


                            }



                        }

                    }

                }

推荐答案

字))
{
cs.Open();


using(SqlDataAdapter da = new SqlDataAdapter(@Select top 25 stationipaddress From machines,cs))
{
3
使用DataAdapter填充DataTable
DataTable t = new DataTable();
da.Fill(t);

4
将数据渲染到屏幕上
dataGridView1.DataSource = t; //< ;-从你的设计师
}


Thread.Sleep(2000);



foreach(DataGridViewRow行。 dataGridView1.Rows)
{
尝试
{

foreach(row.Cells中的DataGridViewCell单元格)
{
if(!cell.Size.IsEmpty)
{


MessageBox.Show(cell.Value.ToString());


ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName =net.exe;
startInfo.Arguments = @use \\+ cell.Value.ToString()+\\c
word")) { cs.Open(); using (SqlDataAdapter da = new SqlDataAdapter(@"Select top 25 stationipaddress From machines", cs)) { 3 Use DataAdapter to fill DataTable DataTable t = new DataTable(); da.Fill(t); 4 Render data onto the screen dataGridView1.DataSource = t; // <-- From your designer } Thread.Sleep(2000); foreach (DataGridViewRow row in this.dataGridView1.Rows) { try { foreach (DataGridViewCell cell in row.Cells) { if (!cell.Size.IsEmpty) { MessageBox.Show(cell.Value.ToString()); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "net.exe"; startInfo.Arguments = @"use \\" + cell.Value.ToString() + "\\c


++密码/用户:admin;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
startInfo.CreateNoWindow = true;
Process.Start(startInfo);

Thread.Sleep(1000);



}
}
}
catch(例外)
{

MessageBox。显示(首次查询完成);
foreach(Data.dridViewRow row1 in this.dataGridView1.Rows)
{
try
{

foreach(row1.Cells中的DataGridViewCell单元格)
{
if(!cell.Size.IsEmpty)
{



int timeout = 5000;


流程流程=新流程();
process.StartInfo.FileName =xcopy;
process.StartInfo.Arguments = textBox1.Text ++ @\\+ cell.Value.ToString()+ @\+ textBox2.Text + @/ C / Y / E / Q / F;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.WaitForExit(timeout);








}
}
}
catch(例外)
{


var compiler = new Process();
compiler.StartInfo.FileName =net.exe;
compiler.StartInfo.Arguments =use * / delete / Y;
compiler.StartInfo.UseShellExecute = true;
compiler.StartInfo.RedirectStandardOutput = false;
compiler.Start();

Thread.Sleep(1000);

MessageBox.Show(Part 1 Copy Done);
cs.Close();


}



}

}

}
" + " " + "Password /user:admin"; startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardInput = true; startInfo.CreateNoWindow = true; Process.Start(startInfo); Thread.Sleep(1000); } } } catch (Exception) { MessageBox.Show("First Query Complete"); foreach (DataGridViewRow row1 in this.dataGridView1.Rows) { try { foreach (DataGridViewCell cell in row1.Cells) { if (!cell.Size.IsEmpty) { int timeout = 5000; Process process = new Process(); process.StartInfo.FileName = "xcopy"; process.StartInfo.Arguments = textBox1.Text + " " + @"\\" + cell.Value.ToString() + @"\" + textBox2.Text + @"/C/Y/E/Q/F"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.StartInfo.CreateNoWindow = true; process.Start(); process.WaitForExit(timeout); } } } catch (Exception) { var compiler = new Process(); compiler.StartInfo.FileName = "net.exe"; compiler.StartInfo.Arguments = "use * /delete /Y"; compiler.StartInfo.UseShellExecute = true; compiler.StartInfo.RedirectStandardOutput = false; compiler.Start(); Thread.Sleep(1000); MessageBox.Show("Part 1 Copy Done"); cs.Close(); } } } }





然后当我尝试将其放入我的ASP.Net Web App时,我会使用以下代码获得以下错误。



错误1无法找到类型或命名空间名称''GridViewCell'(您是否缺少using指令或程序集引用?)





And then when I try to put it in my ASP.Net Web App I get the following errors with the following code.

Error 1 The type or namespace name ''GridViewCell'' could not be found (are you missing a using directive or an assembly reference?)

  using (SqlConnection cs = new SqlConnection(
@"Data Source=100-NUprod-P-001.acds.net;Initial Catalog=Nuprod;Persist Security Info=True;User ID=Nuprod;Password=MyPa


字))
{
cs.Open();


使用(SqlDataAdapter da = new SqlDataAdapter( @ 选择前25个stationipaddress从机器,cs))
{
// 3
// < span class =code-comment>使用DataAdapter填充DataTable
DataTable t = new DataTable();
da.Fill(t);

// 4
// 将数据渲染到屏幕上
GridView1.DataSource = t; // < - 来自您的设计师
}


Thread.Sleep( 2000 );



foreach (GridViewRow行 in < span class =code-keyword> this .GridView1.Rows)
{
try
{

foreach (GridViewCell cell in row.Cells)
{
if (!cell.Size.IsEmpty)
{


// MessageBox.Show(cell.Value.ToString());


ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = net.exe;
startInfo.Arguments = @ 使用\\ + cell.Value.ToString ()+ \\c
word")) { cs.Open(); using (SqlDataAdapter da = new SqlDataAdapter(@"Select top 25 stationipaddress From machines", cs)) { //3 //Use DataAdapter to fill DataTable DataTable t = new DataTable(); da.Fill(t); //4 //Render data onto the screen GridView1.DataSource = t; // <-- From your designer } Thread.Sleep(2000); foreach (GridViewRow row in this.GridView1.Rows) { try { foreach (GridViewCell cell in row.Cells) { if (!cell.Size.IsEmpty) { //MessageBox.Show(cell.Value.ToString()); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "net.exe"; startInfo.Arguments = @"use \\" + cell.Value.ToString() + "\\c


这篇关于Win Form VS Asp.Net Gridview中的Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆