我的项目中有一个Windows窗体用户控件。它一直在没有任何问题的形式上工作,但突然我不能在其他任何形式上使用它。如果我尝试将其从工具箱中拖动到新窗体,则会收到此错误消息
“无法创建控件'controlName'。错误消息如下:system.ArgumentException:在配置中找不到指定的命名连接,不打算与EntityClient提供程序一起使用或无效。”
但是当我运行该项目时,它编译时没有任何错误。
另外,当我想打开已经包含此Usercontrol且运行良好的表单的设计器时,设计器无法加载,并且我在下面看到错误消息
“为了防止在加载设计器之前可能丢失数据,必须解决以下错误:
在配置中找不到指定的命名连接,或者不打算与EntityClient提供程序一起使用,或者无效。
变量'MyControlName1'未声明或从未分配。”
我不了解发生了什么,但该项目仍在构建和运行,但是肯定有严重错误。
下面是我的示例文本文件
{
这是我的架构文件
[Sample File.txt]
ColNameHeader=True
Format=TabDelimited
CharacterSet=ANSI
Run Code Online (Sandbox Code Playgroud)
这是我迄今为止编写的用于尝试读取上述示例文件的代码,从上面的文本文件中读取的数据行应该返回以在 dataGridView 控件中显示。问题是,它作为单列返回,但我想使用这些空格作为列分隔符。我尝试了不同的字符分隔符,但没有成功。
public DataSet LoadCSV(int numberOfRows)
{
DataSet ds = new DataSet();
// Creates and opens an ODBC connection
string strConnString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + this.dirCSV.Trim() + ";Extensions=asc,csv,tab,txt;Persist Security Info=False";
string sql_select;
OdbcConnection conn;
conn = new OdbcConnection(strConnString.Trim());
conn.Open();
//Creates the select command text
if (numberOfRows == -1)
{
sql_select = "select * from [" + this.FileNevCSV.Trim() + "]";
}
else
{
sql_select = "select top " + …Run Code Online (Sandbox Code Playgroud) 我试图使用下面的代码将Excel文件中的数据读入ADO.NET数据集.在Windows窗体应用程序中它可以工作,但在asp.net应用程序中它失败了.
public static DataTable ArchiveData(string fileName)
{
FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read);
//Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
//Free resources (IExcelDataReader is IDisposable)
excelReader.Close();
return result.Tables["Archive data"];
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
[HttpException (0x80004005): Maximum request length exceeded.]
System.Web.HttpRequest.GetEntireRawContent() +8793522
System.Web.HttpRequest.GetMultipartContent() +62
System.Web.HttpRequest.FillInFormCollection() +236
System.Web.HttpRequest.get_Form() +68
System.Web.HttpRequest.get_HasForm() +8745879
System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97
System.Web.UI.Page.DeterminePostBackMode() +63
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +133
Run Code Online (Sandbox Code Playgroud)
或者有更好的方法从客户端计算机读取Excel文件到ASP.NET中的ADO.NET DataTable
我有下面的代码.我如何设置checkListBox项目前颜色取决于是否选中项目?
private void FindSelectedUserRoles()
{
lblSelectedUser.Text = Code.CommonUtilities.getDgvStringColValue(dataGridViewUserList, "UserName").Trim();
//iterate all roles selected user is member of
for (int i = 0; i < checkedListRoles.Items.Count; i++)
{
string roleName = checkedListRoles.Items[i].ToString();
string selectedUserRoles = Code.MemberShipManager.GetSpecificUsersRoles(lblSelectedUser.Text.Trim());
if (selectedUserRoles.Contains(roleName))
{
checkedListRoles.SetItemChecked(i, true);
//here i want to set item fore colour to green
}
else if (selectedUserRoles.Contains(roleName) == false)
{
checkedListRoles.SetItemChecked(i, false);
//and here, i want item fore colour to remain black
}
}
}
Run Code Online (Sandbox Code Playgroud) Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["MyConnectionString",String.Format("DataSource={0};")].ConnectionString=textBox1.Text;
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("connectionStrings");
Run Code Online (Sandbox Code Playgroud)
我在第二行遇到麻烦.我似乎无法使语法正确.如您所见,我只想更新DataSource值.例如,如果当前值是Data Source = PC001\SQL2008EXPRESS,我希望它更新为客户端在textBox1中输入的内容.
编辑:示例ConnectionString
<add name="ERPDatabaseTables" connectionString="metadata=res://*/ERPTables.csdl|res://*/ERPTables.ssdl|res://*/ERPTables.msl;provider=System.Data.SqlClient;provider connection string="Data Source=PC001\SQL2008EXPRESS;Initial Catalog=MyDatabase.mdf;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
Run Code Online (Sandbox Code Playgroud)
所以想要仅更新Data Source = PC001\SQL2008EXPRESS部分
app-config configuration-files winforms entity-framework-4 c#-4.0
Select CONVERT(Date, '13-5-2012')
Run Code Online (Sandbox Code Playgroud)
当我在Management Studio中运行上面的T-SQL语句时,我得到以下错误:
"从字符串转换日期和/或时间时转换失败"
有没有我可以成功地将该值转换为有效的日期类型?我在nvarchar(255)列中有这样的值,其dataType我想在SQL Server表中更改为Date类型但我已经遇到了该错误,我想首先在表上的Update语句中进行转换.
// Browses file with OpenFileDialog control
private void btnFileOpen_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialogCSV = new OpenFileDialog();
openFileDialogCSV.InitialDirectory = Application.ExecutablePath.ToString();
openFileDialogCSV.Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
openFileDialogCSV.FilterIndex = 1;
openFileDialogCSV.RestoreDirectory = true;
if (openFileDialogCSV.ShowDialog() == DialogResult.OK)
{
this.txtFileToImport.Text = openFileDialogCSV.FileName.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我浏览要打开的文件.我想要做的是,浏览文件,选择它,然后按确定.单击确定后,我想复制选择的文件,并为该重复文件提供.txt扩展名.我需要帮助才能实现这一目标.
谢谢
我有两个带有以下表达式的计算列(MonthsInService和YearsInService).
MonthsInService = (datediff(month,[DateEngaged],getdate()))
YearsInService = (datediff(month,[DateEngaged],getdate())/(12))
现在,如果例如DateEngaged = 2012-April-09和getdate()是2013年4月 - 08,则MonthsInService返回12并且YearsInService为1.
我的申请要求YearsInService为零,因为在员工成立一周年之前还有一天要走.
我甚至不确定如何最好地处理MonthsInService列,因为几个月有不同的天数.
MERGE DestinationTable AS D
USING @SourceTable AS S
ON D.Alternate_ID = S._ID
WHEN MATCHED AND
(
D.Candidate_ID <> S.Candidate_ID OR ISNULL(D.Vacancy_ID,'') <> S.Vacancy_ID
)
THEN
UPDATE SET
D.FName = S.FName,
D.Department = S.Department,
WHEN NOT MATCHED BY TARGET
THEN INSERT
(
Alternate_ID,
FName,
Department
)
VALUES
(
S.ID,
S.FName,
S.Department
)
WHEN NOT MATCHED BY SOURCE
--How to add a where clause to the delete statement here
THEN DELETE; --E.g WHERE D.Department <> 'HR'
Run Code Online (Sandbox Code Playgroud)
我正在使用上面的合并声明删除DestinationTable中的记录,如果它们已从源中删除
有没有人知道如何将一个WHERE条件添加到Delete语句?我想只从目标中删除,其中ColA等于特定的常量字符串.
我有一个必须排序的DataTable,但是即使在对DataTable排序之后,我也想返回特定的行作为最后一行。我将通过单列中的字符串值来标识此行。
public DataTable StandardReport3B(string missionId, string reportType, string startDate, string endDate)
{
List<long> missionIdList = new List<long>();
string[] missionIds = missionId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string mission in missionIds)
{
missionIdList.Add(Convert.ToInt64(mission));
}
DataTable dt = new DataTable();
object reportData = null;
using (var ctx = new MedicalServiceEntities())
{
reportData = ctx.GetData(startDate, endDate, missionId).ToList();
}
dt = this.GenericListToDataTable(reportData);
DataView dv = dt.DefaultView;
dv.Sort = dt.Columns[0].ColumnName + " Asc";
return dv.ToTable();
}
Run Code Online (Sandbox Code Playgroud) c# ×5
winforms ×4
t-sql ×3
ado.net ×2
sql-server ×2
app-config ×1
asp.net ×1
c#-4.0 ×1
dataset ×1
datatable ×1
datediff ×1
odbc ×1
sql ×1
text-driver ×1
text-files ×1