如何修复sql查询中的错误 [英] How to fix an error in sql query
问题描述
我正在使用sql在c#中创建数据库应用程序。我试图在数据库中搜索记录,但我有错误。我正在使用的SQL查询是:
从Member中选择*,其中MemberId喜欢@MemberId。这个查询在sql中运行良好,但是当我在c#中的代码中使用时。这是我的代码:
成员f = 新成员();
f.Show();
string str =( @ 数据源= BROTHER-PC;初始目录= iEMYS;集成安全性=真);
SqlConnection con = new SqlConnection(str);
if (comboBox1.SelectedIndex == 0 )
{
尝试
{
string searchtext = textBox1.Text;
int value = int .Parse(textBox1.Text);
if (f.iEMYSDataSet2.Member.Count!= 0 )
{
f.memberTableAdapter.FillByMemberId(f.iEMYSDataSet2.Member, % + int .Parse(searchtext)+ % );
}
if ( this .iEMYSDataSet.Administrator.Count == 0 )
{
MessageBox.Show( 在iEMYS系统中找不到管理员, 管理员信息);
}
}
catch (例外)
{
}
}
我收到此错误:
'iEMYS.iEMYSDataset2TableAdapters.memberTableAdapter的最佳重载方法匹配。 FillByMemberId(iEMYS.iEMYSDataset2.memberDataTable,int)'有一些无效的参数
我需要帮助
< blockquote>获取一个字符串,将其转换为一个整数来调用一个期望整数的方法是一回事:但是你不能再添加strigns并期望它保持一个整数:我应该怎么做呢?
%17%/ 42
数学上,它是垃圾 - 这就是你想要传递给你的方法的东西。
要么传递整数值而不向其添加字符串,要么为你的方法写一个重载而是字符串。
i am creating a database application in c# using sql. i am trying to search records in the database but i having an errors. the sql query i am using is:
Select * from Member where MemberId like @MemberId. this query works well in sql but when i used in my code in c#. this is my code:
Members f = new Members();
f.Show();
string str = (@"Data Source=BROTHER-PC;Initial Catalog=iEMYS;Integrated Security=True");
SqlConnection con = new SqlConnection(str);
if (comboBox1.SelectedIndex == 0)
{
try
{
string searchtext = textBox1.Text;
int value = int.Parse(textBox1.Text);
if (f.iEMYSDataSet2.Member.Count != 0)
{
f.memberTableAdapter.FillByMemberId(f.iEMYSDataSet2.Member, "%" + int.Parse(searchtext) + "%");
}
if (this.iEMYSDataSet.Administrator.Count == 0)
{
MessageBox.Show("No Administrator found in iEMYS System", "Admin Info");
}
}
catch (Exception)
{
}
}
I get this error:
the best overloaded method match for 'iEMYS.iEMYSDataset2TableAdapters.memberTableAdapter.FillByMemberId(iEMYS.iEMYSDataset2.memberDataTable,int)' has some invalid arguments
please I need help
Taking a string, converting it to an integer to call a method expecting an integer is one thing: but you can't then add strigns to it and expect it to remain an integer: what should I do with this?
%17% / 42
Mathematically, it's garbage - and that's what you are trying to pass to your method.
Either pass the integer value without adding strings to it, or write an overload fro your method which takes a string instead.
这篇关于如何修复sql查询中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!