根据下面的代码,我收到以下消息。我相当确定我得到它的“原因”,我只是不知道如何重新排列代码以移动/删除/替换导致错误的语句之一。
“使用/main 编译以指定包含入口点的类型。”
"static void Main(string[] args)" 下有一堆代码,我从 http://support.microsoft.com/kb/816112 为了从自动递增中获取 ID,所以当其余代码填充 Access 数据库时,我可以让它自动递增。任何帮助表示赞赏。也欢迎使用更简单的代码获得结果的建议!
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Hazardous Materials\KinneyDatabase.accdb");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
vcon.Open();
try
{
StreamReader sr = new StreamReader(@"C:\Hazardous Materials\cities.txt");
string line = sr.ReadLine();
StreamReader sr2 = new StreamReader(@"C:\Hazardous Materials\drugs.txt");
string line2 = sr2.ReadLine();
StreamReader sr3 = new StreamReader(@"C:\Hazardous Materials\strengths.txt");
string line3 = sr3.ReadLine();
while (line != null)
{
comboBox1.Items.Add(line);
line = sr.ReadLine();
}
while (line2 != null)
{
comboBox2.Items.Add(line2);
line2 = sr2.ReadLine();
}
while (line3 != null)
{
comboBox3.Items.Add(line3);
line3 = sr3.ReadLine();
}
textBox2.Text = "Date";
}
catch (System.Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private static OleDbCommand cmdGetIdentity;
[STAThread]
static void Main(string[] args)
{
// Open Connection
OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Hazardous Materials\KinneyDatabase.accdb");
vcon.Open();
// If the test table does not exist then create the Table
string strSQL;
strSQL = "CREATE TABLE AutoIncrementTest " +
"(ID int identity, Description varchar(40), " +
"CONSTRAINT AutoIncrementTest_PrimaryKey PRIMARY KEY (ID))";
// Command for Creating Table
OleDbCommand cmdJetDB = new OleDbCommand(strSQL, vcon);
cmdJetDB.ExecuteNonQuery();
// Create a DataAdaptor With Insert Command For inserting records
OleDbDataAdapter oleDa = new OleDbDataAdapter("Select * from AutoIncrementTest", vcon);
// Command to Insert Records
OleDbCommand cmdInsert = new OleDbCommand();
cmdInsert.CommandText = "INSERT INTO AutoIncrementTest (Description) VALUES (?)";
cmdInsert.Connection = vcon;
cmdInsert.Parameters.Add(new OleDbParameter("Description", OleDbType.VarChar, 40, "Description"));
oleDa.InsertCommand = cmdInsert;
// Create a DataTable
DataTable dtTest = new DataTable();
oleDa.Fill(dtTest);
DataRow drTest;
// Add Rows to the Table
drTest = dtTest.NewRow();
drTest["Description"] = "This is a Test Row 1";
dtTest.Rows.Add(drTest);
drTest = dtTest.NewRow();
drTest["Description"] = "This is a Test Row 2";
dtTest.Rows.Add(drTest);
// Create another Command to get IDENTITY Value
cmdGetIdentity = new OleDbCommand();
cmdGetIdentity.CommandText = "SELECT @@IDENTITY";
cmdGetIdentity.Connection = vcon;
// Delegate for Handling RowUpdated event
oleDa.RowUpdated += new OleDbRowUpdatedEventHandler(HandleRowUpdated);
// Update the Data
oleDa.Update(dtTest);
// Drop the table
cmdJetDB.CommandText = "DROP TABLE AutoIncrementTest";
cmdJetDB.ExecuteNonQuery();
// Release the Resources
cmdGetIdentity = null;
cmdInsert = null;
cmdJetDB = null;
vcon.Close();
vcon = null;
}
// Event Handler for RowUpdated Event
private static void HandleRowUpdated(object sender, OleDbRowUpdatedEventArgs e)
{
if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert )
{
// Get the Identity column value
e.Row["ID"] = Int32.Parse(cmdGetIdentity.ExecuteScalar().ToString());
System.Diagnostics.Debug.WriteLine(e.Row["ID"]);
e.Row.AcceptChanges();
}
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex <= 0)
{
MessageBox.Show("All fields must be filled out to submit the form");
}
else if (comboBox2.SelectedIndex <= 0)
{
MessageBox.Show("All fields must be filled out to submit the form");
}
string addRemove = "";
//string toFrom = "";
if (radioButton1.Checked)
{
addRemove = "add";
//toFrom = "to";
}
else if (radioButton2.Checked)
{
addRemove = "remove";
//toFrom = "from";
}
float mgTotal = (float.Parse(textBox1.Text) * float.Parse(comboBox3.Text));
MessageBox.Show("You have entered the following information: \n\n"
+ "\n" + "Location: " + float.Parse(comboBox1.Text)
+ "\n" + "Medication: " + comboBox2.Text
+ "\n" + "Quantity " + textBox2.Text
+ "\n" + "Strength " + float.Parse(comboBox3.Text)
+ "\n" + "Initials: " + textBox3.Text
+ "\n" + "Add or Remove: " + addRemove
+ "\n" + "Date: " + textBox2.Text);
}
private void button2_Click(object sender, EventArgs e)
{
new Form2().Show();
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
MessageBox.Show("Produced for use by HealthDirect© \n Scripted by Geoff Bertollini. March 2012");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox3.SelectedIndex = comboBox2.SelectedIndex;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
var date = DateTime.Now.ToString("MM/dd/yyyy");
textBox2.Text = date;
}
private void label4_Click_1(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button4_Click(object sender, EventArgs e)
{
string addRemove = "";
string toFrom = "";
if (radioButton1.Checked)
{
addRemove = "added";
toFrom = "to";
}
else if (radioButton2.Checked)
{
addRemove = "removed";
toFrom = "from";
}
float mgTotal = (float.Parse(textBox1.Text) * float.Parse(comboBox3.Text));
string vsql = string.Format("insert into Log values " +
"('{0}','{1}',{2},{3},'{4}',#{5}#,'{6}','{7}')",
comboBox1.Text,
comboBox2.Text,
float.Parse(textBox1.Text),
float.Parse(comboBox3.Text),
textBox3.Text,
textBox2.Text,
addRemove,
"1"
);
OleDbCommand vcom = new OleDbCommand(vsql, vcon);
vcom.ExecuteNonQuery();
MessageBox.Show("Date: " + textBox2.Text + "\n Initials: " + textBox3.Text
+ "\n" + "You have " + addRemove + " " + mgTotal + " milligrams " + "\n"
+ "of " + comboBox2.Text + "\n" + toFrom + " the inventory of \n" + comboBox1.Text);
vcom.Dispose();
}
}
}
最佳答案
没有一个答案开门见山。
项目的属性对话框,通过右键单击项目 Access ,有一个应用程序选项卡。在此选项卡上有一个“启动对象”下拉列表——只需选择 Visual Studio 应定位的正确类文件。只要该类文件中有 Main static void 事件,它就会以它为目标。确保 Main 是大写的。这行不通:
静态无效主要(字符串[]参数) { ... 代码 ...
这是一张图片:
在网络项目中,您可以右键单击一个 ASPX 文件并将其设置为启动页,非常相似。为什么 Visual Studio 隐藏此设置没有意义,但这就是您的做法。
关于c# - "Compile with/main to specify the type that contains the entry point.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9897371/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha
我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas