C# "conn"方法没有采用"0"个参数的重载、新手求答- -
publicstaticstringconn(stringi){stringoutput="";Processp=newProcess();p.StartInfo.Fil...
public static string conn(string i)
{
string output = "";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("nslookup dns.s.tooo");
p.StandardInput.WriteLine("exit");
output = p.StandardOutput.ReadToEnd();
i = output.Substring(output.LastIndexOf("Address:") + 10);
i= (i.Substring(0, 16)).Trim();
return i;
}
private void btnDl_Click(object sender, EventArgs e)
{
if (txtId.Text.Length == 0 || txtPwd.Text.Length == 0) { return; }
imgLoadding.Visible = true;
btnDl.Enabled = false;
bool error = false;
int num = 0; // 数据库操作结果
try
{
string connString = "Data Source='" + conn().Trim + "';Initial Catalog=MyQQ;User ID=sa;Pwd=cnmbxld0618123.";
SqlConnection connection = new SqlConnection(connString);
// 查询用的sql语句
string sql = string.Format("SELECT COUNT(*) FROM Users WHERE Id={0} AND LoginPwd = '{1}'",
。。。。。。。。
}
}
= =string connString = "Data Source=........这句出错 展开
{
string output = "";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("nslookup dns.s.tooo");
p.StandardInput.WriteLine("exit");
output = p.StandardOutput.ReadToEnd();
i = output.Substring(output.LastIndexOf("Address:") + 10);
i= (i.Substring(0, 16)).Trim();
return i;
}
private void btnDl_Click(object sender, EventArgs e)
{
if (txtId.Text.Length == 0 || txtPwd.Text.Length == 0) { return; }
imgLoadding.Visible = true;
btnDl.Enabled = false;
bool error = false;
int num = 0; // 数据库操作结果
try
{
string connString = "Data Source='" + conn().Trim + "';Initial Catalog=MyQQ;User ID=sa;Pwd=cnmbxld0618123.";
SqlConnection connection = new SqlConnection(connString);
// 查询用的sql语句
string sql = string.Format("SELECT COUNT(*) FROM Users WHERE Id={0} AND LoginPwd = '{1}'",
。。。。。。。。
}
}
= =string connString = "Data Source=........这句出错 展开
2个回答
展开全部
你的定义是public static string conn(string i),那你调用的时候就必须给它一个string的参数,比如conn("2"),但是从你上面函数看,这个i完全没意义的,修改如下
1、 public static string conn(string i)
修改为
public static string conn()
2、 i = output.Substring(output.LastIndexOf("Address:") + 10);
i= (i.Substring(0, 16)).Trim();
return i;
这三行修改为
return output.Substring(output.LastIndexOf("Address:") + 10).Trim();
3、 string connString = "Data Source='" + conn().Trim + "';Initial Catalog=MyQQ;User ID=sa;Pwd=cnmbxld0618123.";
修改为
string connString = "Data Source='" + conn() + "';Initial Catalog=MyQQ;User ID=sa;Pwd=cnmbxld0618123.";
1、 public static string conn(string i)
修改为
public static string conn()
2、 i = output.Substring(output.LastIndexOf("Address:") + 10);
i= (i.Substring(0, 16)).Trim();
return i;
这三行修改为
return output.Substring(output.LastIndexOf("Address:") + 10).Trim();
3、 string connString = "Data Source='" + conn().Trim + "';Initial Catalog=MyQQ;User ID=sa;Pwd=cnmbxld0618123.";
修改为
string connString = "Data Source='" + conn() + "';Initial Catalog=MyQQ;User ID=sa;Pwd=cnmbxld0618123.";
展开全部
conn函数需要一个参数
追问
= =能详细点嘛
追答
change conn() like this
public static string conn()
{
string i = "";
string output = "";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("nslookup dns.s.tooo");
p.StandardInput.WriteLine("exit");
output = p.StandardOutput.ReadToEnd();
i = output.Substring(output.LastIndexOf("Address:") + 10);
i = (i.Substring(0, 16)).Trim();
return i;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询