Click here to Skip to main content
15,902,189 members

Comments by shonezi (Top 150 by date)

shonezi 27-Dec-13 5:46am View    
forget I asked, found a solution, and not my credit of course for this idiotic question I had

text1 = text.Replace(@" ", "_");

so stupid for asking while people have serious issues to deal with
shonezi 9-Dec-13 7:38am View    
thank you again
shonezi 9-Dec-13 7:16am View    
sorry for bothering you all , I found solution, this works, thank you all, thank you

foreach (DataGridViewRow row in dgImport.Rows)
{
if (string.IsNullOrEmpty(row.Cells["Potrosnja"].Value.ToString()) == true)
{
row.Cells["Expense"].Value = 0;
}

}
dgImport.Refresh();
shonezi 9-Dec-13 6:55am View    
I can show the code for importing

OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Title = "Select file";
openDialog.Filter = "Excel Sheet(*.xls)|*.xls|All Files(*.*)|*.*";
openDialog.FilterIndex = 1;
openDialog.RestoreDirectory = true;
if (openDialog.ShowDialog() == DialogResult.OK)
{
if (openDialog.FileName != "")
{
textBox1.Text = openDialog.FileName;
cmbExcelSheet.DataSource = GetExcelSheetNames(openDialog.FileName);
foreach (string s in cmbExcelSheet.Items)
{
cmbExcelSheet1.ComboBox.Items.Add(s);
}

}

else
{
MessageBox.Show("Choose Excel sheet path..", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

and GetExcelSheetNames

private String[] GetExcelSheetNames(string excelFile)
{
OleDbConnection objConn = null;
System.Data.DataTable dt = null;

try
{
// Connection String. Change the excel file to the file you

// will search.

String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
// Create connection object by using the preceding connection string.

objConn = new OleDbConnection(connString);
// Open connection with the database.

objConn.Open();
// Get the data table containg the schema guid.

dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

if (dt == null)
{
return null;
}

String[] excelSheets = new String[dt.Rows.Count];
int i = 0;

// Add the sheet name to the string array.

foreach (DataRow row in dt.Rows)
{
excelSheets[i] = row["TABLE_NAME"].ToString();
i++;
}

// Loop through all of the sheets if you want too...

for (int j = 0; j < excelSheets.Length; j++)
{
// Query each excel sheet.

}

return excelSheets;
}
catch (Exception ex)
{
return null;
}
finally
{
// Clean up.

if (objConn != null)
{
objConn.Close();
objConn.Dispose();
}
if (dt != null)
{
dt.Dispose();
}
}
}
shonezi 22-Nov-13 5:03am View    
I have done that, found it :) griff thank you, for help and patience