导出excel后,此代码总是跳过最后一行,你能检查一下代码中的错误吗?
我变了
transcationTableDataGridView.Rows.Count - 1
Run Code Online (Sandbox Code Playgroud)
至
transcationTableDataGridView.Rows.Count + 1
Run Code Online (Sandbox Code Playgroud)
它确实将所有行导出为excel但抛出索引应为非负错误此异常: 
private void exportToExcel_Click(object sender, EventArgs e)
{
try
{
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
app.Visible = true;
worksheet = workbook.Sheets["Sheet1"];
worksheet = workbook.ActiveSheet;
worksheet.Name = "Records";
try
{
for (int i = 1; i < transcationTableDataGridView.Columns.Count + 1; i++)
{
worksheet.Cells[1, i] = transcationTableDataGridView.Columns[i - 1].HeaderText;
}
for (int i = 0; i < transcationTableDataGridView.Rows.Count - 1; i++)
{
for (int j …Run Code Online (Sandbox Code Playgroud) 我正在尝试从另一个按钮调用 datagridview 单元格事件方法。
DataGridView 单元格双击方法
private void ListDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
ListDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
DataGridViewRow row = this.ListDataGridView.Rows[e.RowIndex];
comboBox2.Text = row.Cells[1].Value.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我调用此方法的按钮
private void button6_Click(object sender, EventArgs e)
{
ListDataGridView_CellDoubleClick(sender, e);
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误
错误 3 命名空间“System”中不存在类型或命名空间名称“DataGridViewCellEventHandler”(您是否缺少程序集引用?)C:\VisualC#\Projects\DataGridViewApplication\DataGridViewApplication\List.Designer.cs 340 46 DataGridViewApplication
我做了什么:
我将 EventArgs 更改为 DataGridViewCellEventArgs。
private void button6_Click(object sender, DataGridViewCellEventArgs e)
{
ListDataGridView_CellDoubleClick(sender, e);
}
Run Code Online (Sandbox Code Playgroud)
现在我收到错误:
this.button6.Click += new System.EventHandler(this.button6_Click);
Run Code Online (Sandbox Code Playgroud)
错误 3 “button6_Click”没有重载匹配委托“System.EventHandler”
C:\VisualC#\Projects\DataGridViewApplication\DataGridViewApplication\List.Designer.cs 340 35 DataGridViewApplication
现在我将按钮事件处理程序代码更改为此
this.button6.Click += new System.DataGridViewCellEventHandler(this.button6_Click);
Run Code Online (Sandbox Code Playgroud)
仍然收到此错误并卡在此处 …
我是SQL Queries的新手,我想从SettlementTypeSetup(表)加载"PSX LAGA"值,其中结算类型等于Regular/BO,Sale/Purchase等于"Purchase";
下面是我的代码,这是我的表
private void Load_Settlement_Type()
{
SqlCeConnection conn = null;
SqlCeCommand cmd = null;
SqlCeDataReader rdr = null;
try
{
conn =
new SqlCeConnection(
@"Data Source=|DataDirectory|\Database.sdf;Persist Security Info=False");
conn.Open();
cmd = new SqlCeCommand("SELECT PSXLaga FROM SettlementTypeSetup where SettlementType=BO/REGULAR;" , conn);
rdr = cmd.ExecuteReader();
if (rdr == null)
{
MessageBox.Show("Reader is null");
}
else
{
while (rdr.Read())
{
PSXLAGATEXT = rdr["PSXLaga"].ToString();
}
rdr.Close();
cmd.Dispose();
}
}
finally
{
conn.Close();
PSXLagaTextBox.Text = PSXLAGATEXT;
}
}
Run Code Online (Sandbox Code Playgroud)
****它给出了错误:列名:BO/REGULAR未找到,而BO/REGULAR不是列名,BO/REGULAR是SettlementType(Column)的值,条件应如下所示.**
给我PSX Laga Value,其中SettlementType(Column)值为BO/REGULAR,Sale/Purchase(Column)为Purchase.
**
我正在生成book serial no和保存到keyvalue对,然后保存到文本文件,每个键都是唯一的.
当我将它保存到文本文件时,生成密钥,我可以检索密钥,它工作正常.
生成密钥:
private void GenerateButton1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
BookcomboBox2.Items.Clear();
from = int.Parse(FrmtextBox1.Text);
to = int.Parse(TotextBox2.Text);
result = to - from;
for (int i = 0; i <= result; i++)
{
string item = Convert.ToString(from + i);
BookcomboBox2.Items.Add(item);
vals.Add(new KeyValuePair<int, string>(0, item)); //
}
MessageBox.Show("Book No 1, Generated Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (comboBox1.SelectedIndex == 1)
{
BookcomboBox2.Items.Clear();
from = int.Parse(FrmtextBox1.Text);
to = int.Parse(TotextBox2.Text);
result = to - from;
for …Run Code Online (Sandbox Code Playgroud) 我已经尝试了几个小时,但在这个 sql 查询中找不到错误,出现异常“<”
Connection con = new OrderManager.Connection();
SqlCommand cmd = new SqlCommand();
string query = @"INSERT INTO [MasterDatabase].[dbo].[Neworder]
([OrderID]
,[Date]
,[Customer_Name]
,[Quality]
,[Color]
,[PCs]
,[Cutting]
,[TotalYards])
VALUES
(<OrderID, nvarchar(50),>
,<Date, varchar(25),>
,<Customer_Name, varchar(25),>
,<Quality, varchar(25),>
,<Color, varchar(25),>
,<PCs, varchar(25),>
,<Cutting, varchar(25),>
,<TotalYards, varchar(25),>)";
cmd = new SqlCommand(query, con.ActiveCon());
cmd.Parameters.AddWithValue("@OrderID", TxtBox_OrderID.Text);
cmd.Parameters.AddWithValue("@Date", dateTimePicker1.Value.ToString());
cmd.Parameters.AddWithValue("@Customer_Name", txtbox_CusName.Text);
cmd.Parameters.AddWithValue("@Quality", combo_Quality.Text);
cmd.Parameters.AddWithValue("@Color", combo_Color.Text);
cmd.Parameters.AddWithValue("@PCs", updown_PCs.Text);
cmd.Parameters.AddWithValue("@Cutting", combo_Cutting.Text);
cmd.Parameters.AddWithValue("@TotalYards", "Total Yards");
Run Code Online (Sandbox Code Playgroud)
cmd.ExecuteNonQuery(); // 这是抛出错误的地方
MessageBox.Show("Record Inserted", "Record Entered Successfully!");
Run Code Online (Sandbox Code Playgroud)
我也尝试使用这个但同样的问题。
string query = @"INSERT INTO …Run Code Online (Sandbox Code Playgroud)