我正在尝试提供查询结果,但我一直在获取空白数据网格.这就像数据本身不可见
这是我的代码:
private void Employee_Report_Load(object sender, EventArgs e)
{
string select = "SELECT * FROM tblEmployee";
Connection c = new Connection();
SqlDataAdapter dataAdapter = new SqlDataAdapter(select, c.con); //c.con is the connection string
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
dataGridView1.ReadOnly = true;
dataGridView1.DataSource = bindingSource1;
}
Run Code Online (Sandbox Code Playgroud)
这段代码出了什么问题?
假设我有一个加权图,在边和顶点上都有权重。如何找到从某个节点s到某个节点t的“最便宜”路径?我的复杂度应为O(n 2(n + m))。
language-agnostic algorithm performance complexity-theory graph
我正在尝试实现一个方法:
public Referee GetRefereeById(int refereeId)
{
var result = from b in Referees
where b.PersonId.Equals(refereeId)
select b;
return (Referee)result;
}
Run Code Online (Sandbox Code Playgroud)
该方法应该返回一个裁判对象.知道我做错了什么吗?
我正在尝试连接到数据库,我收到以下错误:
路径中的非法字符.
这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
SqlConnection Con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\targil3.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlDataAdapter adapt = new SqlDataAdapter();
adapt.InsertCommand = new SqlCommand(" INSERT INTO tblEmployee VALUES (@employeeNumber, @employeePrivateName, @employeeFamilyName ,@city, @street, @houseNo, @phoneNumber, @birthDate, @startWorkingDate)", Con);
adapt.InsertCommand.Parameters.Add("@employeeNumber", SqlDbType.Char).Value = textBox1.Text;
adapt.InsertCommand.Parameters.Add("@employeePrivateName", SqlDbType.VarChar).Value = textBox2.Text;
adapt.InsertCommand.Parameters.Add("@employeeFamilyName", SqlDbType.VarChar).Value = textBox3.Text;
adapt.InsertCommand.Parameters.Add("@city", SqlDbType.VarChar).Value = textBox4.Text;
adapt.InsertCommand.Parameters.Add("@street", SqlDbType.VarChar).Value = textBox5.Text;
adapt.InsertCommand.Parameters.Add("@houseNo", SqlDbType.Int).Value = textBox6.Text;
adapt.InsertCommand.Parameters.Add("@phoneNumber", SqlDbType.Char).Value = textBox7.Text;
adapt.InsertCommand.Parameters.Add("@birthDate", SqlDbType.DateTime).Value = Convert.ToDateTime(textBox8.Text);
adapt.InsertCommand.Parameters.Add("@startWorkingDate", SqlDbType.DateTime).Value = Convert.ToDateTime(textBox8.Text);
Con.Open();
adapt.InsertCommand.ExecuteNonQuery(); …Run Code Online (Sandbox Code Playgroud) 我正在研究本地项目并尝试连接到本地数据库.我有这个类的连接字符串:
public class SQLConnection
{
public static string connectionString =
@"Data Source=TZVIKA-PC\SQLEXPRESS;Initial Catalog=WorldCup;Integrated Security=True";
public static WorldCupDBDataContext wcDataContext =
new WorldCupDBDataContext(connectionString);
public static WorldCupDBDataContext GetDataContextInstance()
{
return wcDataContext;
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在Windows窗体中执行此行时:
teamBindingSource.DataSource = database.Teams.OrderBy(team => team.TeamId);
Run Code Online (Sandbox Code Playgroud)
我得到以下sql异常:
建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称是否正确,以及SQL Server是否配置为允许远程连接.(提供程序:SQL网络接口,错误:26 - 查找指定的服务器/实例时出错)
我的朋友运行了代码,它可以在他的电脑上运行(当然将连接字符串更改为相关的字符串时)
为什么它不适合我?
c# ×4
sql-server ×2
.net ×1
algorithm ×1
database ×1
datagridview ×1
graph ×1
linq ×1
performance ×1
sql ×1
winforms ×1