我正在创建一个实用程序,在执行一些计算后将少量记录插入到SQL中.我正在使用后台工作程序来阻止应用程序进入无响应状态.随着流程的工作,我需要更改几个标签值,我使用委托.是否可以将我的标签作为参数传递给具有委托的函数,以便我可以重用一些代码?
下面是我用来更改label2的值的函数.对于label3,我使用了几乎相同的另一个函数.是否可以创建一个接受label作为参数的函数,以便我可以传递控件名称和所需的消息,并为我做更新?
这是我更改label2的代码:
public void changelabel(string msg)
{
if (label2.InvokeRequired)
label2.Invoke(new MethodInvoker(delegate
{
label2.Text = msg;
}));
else
label2.Text = msg;
}
Run Code Online (Sandbox Code Playgroud) static void Main(string[] args)
{
string str_val = "8584348,894";
//int prefix = Convert.ToInt32(str_val[0]); //prefix = 56 O_o
//int prefix = (int)str_val[0]; //what, again 56? i need 8!
int prefix = Convert.ToInt32("8"); //at least this works -_-
}
Run Code Online (Sandbox Code Playgroud)
知道如何将第一个符号转换为正确的数值?
我有一个查询,我想添加参数来计算移动年度(过去12个月的数字).我试图从今天开始减去12个月,所以如果今天是2012年8月1日那么我的@StartDate应该是'2011-09-01'而我的@EndDate应该是'2012-08-31'.那么如何更改设置我的参数以适应这个?
declare @StartDate DATE
declare @EndDate DATE
SET @StartDate = DATEADD(MONTH, -12, '2012-08-01')
SET @EndDate = DATEADD(MONTH, +1, '2012-08-01')
Run Code Online (Sandbox Code Playgroud) 我有一个返回的Web服务List<SampleClass>.我使用LINQ-to-SQL从数据库中获取数据IEnumerable<SampleClass>.然后转换IEnumerable<SampleClass>为List<SampleClass>.
LINQ到SQL操作表现还算可以,但IEnumerable<SampleClass>要List<SampleClass>花费一些时间来做手术.是否有任何解决方案,从获得最佳的性能IEnumerable<SampleClass>来List<SampleClass>?
我从我的数据库中读取了超过3000条记录.
谢谢
当我使用下面的代码时,循环迭代两次,我收到错误消息"变量名'@ projectName1'已经被声明.变量名在查询批处理或存储过程中必须是唯一的." 并重置datagridview和表中的表的所有值.实际上我想通过选择单元格来更新表单中的DataGridView,它也应该在数据库中反映出来.
private void btnUpdate_Click(object sender, EventArgs e)
{
SqlConnection con = Helper.getconnection();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
string myCmd = string.Empty;
foreach (DataGridViewRow myDgrow in dataGridView2.Rows)
{
myCmd = "Update Details set ProjectName='" + myDgrow.Cells["ProjectName"].Value + "', Description = '" + myDgrow.Cells["Description"].Value + "', DateStarted='" + myDgrow.Cells["DateStarted"].Value + "',TeamSize='" + myDgrow.Cells["TeamSize"].Value + "',Manager='" + myDgrow.Cells["Manager"].Value + "'";
cmd.Parameters.AddWithValue("@projectName1", myDgrow.Cells["ProjectName"].Value);
cmd.Parameters.AddWithValue("@Description1", myDgrow.Cells["Description"].Value);
cmd.Parameters.AddWithValue("@DateStarted1", myDgrow.Cells["DateStarted"].Value);
cmd.Parameters.AddWithValue("@TeamSize1", myDgrow.Cells["TeamSize"].Value);
cmd.Parameters.AddWithValue("@Manager1", myDgrow.Cells["Manager"].Value);
cmd.CommandText = myCmd;
cmd.ExecuteNonQuery();
dataGridView2.Update();
myCmd = …Run Code Online (Sandbox Code Playgroud) 我想知道列表是否是第二个列表的前缀,使用以下代码:
prefix :: [a] -> [b] -> Bool
prefix [] _ = True
prefix _ [] = False
prefix (x:xs) (y:ys) = if (x==y) then prefix xs ys else False
Run Code Online (Sandbox Code Playgroud)
但它返回一个错误:
Inferred type is not general enough
*** Expression : prefix
*** Expected type : [a] -> [b] -> Bool
*** Inferred type : [a] -> [a] -> Bool
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我让这个工作吗?
我有两个表需要连接,但唯一相似的列有多余的数据需要被删除.我只想修改表,但我只能读取它们.因此,我从表中删除不需要的文本并添加临时列,但我无法加入它.我收到错误:
列名称'TempJoin'无效
SELECT
CASE WHEN CHARINDEX('- ExtraText',a.Column1)>0 THEN LEFT(a.Column1, (CHARINDEX('- ExtraText', a.Column1))-1)
WHEN CHARINDEX('- ExtraText',a.Column1)=0 THEN a.Column1
END AS TempJoin
,a.Column1
,b.Column2
FROM Table1 as a
LEFT JOIN Table2 as b WITH(NOLOCK) ON b.Column2=TempJoin
Run Code Online (Sandbox Code Playgroud) 所以,我正在尝试创建一个触发器,如果外键代码无效,将在插入数据时抛出错误.我有两个表,Publisher和Title.标题上有发布者代码,Publisher也是如此.我在我的Title for insert上有触发器,我目前正在执行if if not exists并选择Publisher行,其中代码等于插入行的发布者代码.我不知道这是否是正确的方法,而且可能不是,因为SQL给了我一个"多部分标识符Inserted.PublisherCode无法找到"错误.你们可以给予的任何帮助将不胜感激.谢谢.
go
create trigger TR_Title_PublisherCode_Insert
on title
for Insert
as
if not exists(select * from Publisher where PublisherCode = Inserted.PublisherCode)
begin
raiserror('Publisher does not exist', 16, 1)
rollback tran
end
Run Code Online (Sandbox Code Playgroud) 只是在SQL Server中使用子查询(我知道这个问题不必用子查询完成,但我想知道我的语法问题在哪里)
select count(*) from
( select id, totalcharges from tblVisits where (totalcharges <10000))
Run Code Online (Sandbox Code Playgroud)