2
The following I have a gridviewer that is connected to a Query with a
Table called Server Table.
I want to add some things to the columns gives the following error
Instance failure.
In this part of the code
connection.Open();
This is part of the code adds the values to the colnas
var nothing = Resources.Nothing;
string domain2 = Domain + "\\" + TxtBoxUpload.Text;
if (TxtBoxUpload.Text == "" || TxtBoxUpload.Text == "Upload Name" || System.IO.Directory.Exists(domain2))
{
MessageBox.Show("Please Insert a valid name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
if (System.IO.Directory.Exists(Domain))
{
if (System.IO.Directory.Exists(domain2))
{
MessageBox.Show("You have a project that you didnt give a name please give it a name and try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
System.IO.Directory.Move(folderBrowserDialog1.SelectedPath, domain2);
string connectionString = @"Data Source=VBSS019\\ZONESOFTSQL;Initial Catalog=ServerDown;Integrated Security=True";
SqlConnection connection = new SqlConnection(connectionString);
cmd.CommandText = "INSERT INTO ServerTable(Icon, [Project Name], Directory) VALUES (@Icon, @[Project Name], @Directory)";
cmd.Parameters.Add("@Icon", nothing);
cmd.Parameters.Add("@[Project Name]", TxtBoxUpload.Text);
cmd.Parameters.Add("@Directory", domain2);
connection.Open(); //Esta é a parte do erro
cmd.ExecuteNonQuery();
}
}
else
{
System.IO.Directory.CreateDirectory(Domain);
try
{
System.IO.Directory.Move(folderBrowserDialog1.SelectedPath, domain2);
Grid.Rows.Add(new object[] { nothing, "Edit", domain2 });
}
catch (Exception ex)
{
MessageBox.Show("Faild to move the file maybe it already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
else
{
}
}
}
This part is that shows the gridviewer
private void Form1_Load(object sender, EventArgs e)
{
Data();
}
public void Data()
{
SqlConnection con = new SqlConnection("Data Source=VBSS019\\ZONESOFTSQL;Initial Catalog=ServerDown;Integrated Security=True");
sda = new SqlDataAdapter(@"SELECT Icon, [Project Name], Directory
FROM ServerTable", con);
dt = new DataTable();
sda.Fill(dt);
Grid.DataSource = dt;
}
thanks but now I’m having the second mistake
ExecuteNonQuery: A propriedade Connection não foi inicializada.
– Pedro
@Pedro You have defined the connection of
Sqlcommand
?cmd.Connection = connection
beforeconnection.Open
.– stderr
I have now appeared your error There is no mapping of the System.Drawing.Icon object type to a native type of known managed vendor. this here the code
– Pedro
System.IO.Directory.Move(folderBrowserDialog1.SelectedPath, domain2);
string connectionString = @"Data Source=VBSS019\ZONESOFTSQL;Initial Catalog=ServerDown;Integrated Security=True";
SqlConnection connection = new SqlConnection(connectionString);
cmd.CommandText = "INSERT INTO ServerTable(Icon, [Project Name], Directory) VALUES (@Icon, @[Project Name], @Directory)";
cmd.Parameters.Add("@Icon", nothing);
cmd.Parameters.Add("@[Project Name]", TxtBoxUpload.Text);
cmd.Parameters.Add("@Directory", domain2);
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
– Pedro
@Pedro If you can, open a question again with this doubt, because this error is different from the main error of the question!
– stderr
If I’ve figured out the mistake is the about the icon I’ll try to fix if I can’t tomorrow I open a new question
– Pedro