我写了一个跟数据库表结构一样的Table 然后放进一个DataSet里面 在下面按键事件里使用QuestionDataSet()方法
为什么所以的DataRow都是空的啊 我已经给他们赋值了啊DataTable dtQuestion = new DataTable("Question");
public string QuestionDataSet()
{
DataColumn question = new DataColumn("Question", typeof(string));
question.MaxLength = 200;
dtQuestion.Columns.Add(question);//DataRow drQuestion = dtQuestion.NewRow();
drQuestion["Question"] = this.rbxQuestion.Text.Trim();
dtQuestion.Rows.Add(drQuestion);
DataSet dsQuestion = new DataSet();
dsQuestion.Tables.Add(dtQuestion);
} private void btnAdd_Click(object sender, EventArgs e)
{
if (checkNull())
{
subManage.NewSub(QuestionDataSet(), this.rbxQuestion);
}
}
为什么所以的DataRow都是空的啊 我已经给他们赋值了啊DataTable dtQuestion = new DataTable("Question");
public string QuestionDataSet()
{
DataColumn question = new DataColumn("Question", typeof(string));
question.MaxLength = 200;
dtQuestion.Columns.Add(question);//DataRow drQuestion = dtQuestion.NewRow();
drQuestion["Question"] = this.rbxQuestion.Text.Trim();
dtQuestion.Rows.Add(drQuestion);
DataSet dsQuestion = new DataSet();
dsQuestion.Tables.Add(dtQuestion);
} private void btnAdd_Click(object sender, EventArgs e)
{
if (checkNull())
{
subManage.NewSub(QuestionDataSet(), this.rbxQuestion);
}
}
解决方案 »
- DataGridViewComboBoxColumn怎么结束编辑
- 求个C#能显示和抓取摄像头图像的小程序
- 读Oracle数据库Clob字段你们都很慢吗?
- 如果一个委托中委托了多个函数,执行该委托时如何确定执行其中的一个?
- SQL2005服务器资源管理器 在那呀
- winform 通过键盘触发按钮事件后,如何获取datagridview内checkbox是否选择
- 急急急,关于C# WINDOWS绘制表格问题
- 关于C#里的怎么又继承一个类又实现一个接口
- 请高手指点,一个很怪的数据库操作问题~!
- 熟悉Remoting的请进
- char byte decimal long sbyte short uint ulong ushort数据类型用来存放什么样的数据?能举几个例子吗谢谢
- sql 查询重复数据的问题
把用户界面接受的参数放进上面的DataSet里面然后传给sql语句
不知道这样调用对不对`
public string QuestionDataSet()
是不是应该改成
public DataSet QuestionDataSet()
返回值是string 型的..
你没有返回值怎么能用??
public DataSet QuestionDataSet()
{
DataColumn question = new DataColumn("Question", typeof(string));
question.MaxLength = 200;
dtQuestion.Columns.Add(question);// DataRow drQuestion = dtQuestion.NewRow();
drQuestion["Question"] = this.rbxQuestion.Text.Trim();
dtQuestion.Rows.Add(drQuestion);
DataSet dsQuestion = new DataSet();
dsQuestion.Tables.Add(dtQuestion);
return dsQuestion;
} private void btnAdd_Click(object sender, EventArgs e)
{
if (checkNull())
{
subManage.NewSub(QuestionDataSet(), this.rbxQuestion);
}
}
上面那段代码是这样的 return dsQuestion;里面的值是空的!
难道是这里错了么?
{
int count;
string sql = "insert into Question values(@Question,@Answer, @Difficulty ,@SubjectId,@OptionA ,@OptionB,@OptionC ,@OptionD)";
SqlConnection conn = new SqlConnection(conStr);
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@Question", SqlDbType.VarChar, 200).Value = ds.Tables["Question"].Rows[0]["Question"];
cmd.Parameters.Add("@Answer", SqlDbType.VarChar, 100).Value = ds.Tables["Question"].Rows[0]["Answer"];
cmd.Parameters.Add("@Difficulty", SqlDbType.Int, 4).Value = ds.Tables["Question"].Rows[0]["Difficulty"];
cmd.Parameters.Add("@SubjectId", SqlDbType.Int, 4).Value = ds.Tables["Question"].Rows[0]["SubjectId"];
cmd.Parameters.Add("@OptionA", SqlDbType.VarChar, 100).Value = ds.Tables["Question"].Rows[0]["OptionA"];
cmd.Parameters.Add("@OptionB", SqlDbType.VarChar, 100).Value = ds.Tables["Question"].Rows[0]["OptionB"];
cmd.Parameters.Add("@OptionC", SqlDbType.VarChar, 100).Value = ds.Tables["Question"].Rows[0]["OptionC"];
cmd.Parameters.Add("@OptionD", SqlDbType.VarChar, 100).Value = ds.Tables["Question"].Rows[0]["OptionD"];
conn.Open();
count= cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
return count;
}
public class NewSubManage
{
NewSubService newSubService = new NewSubService(); public DataSet GetAllSub()
{
return newSubService.GetAllSub();
} public string NewSub(DataSet ds,string questionName)
{
string massage = string.Empty; if(newSubService.GetAllQuestion(questionName)!=0)
{
massage = "已经存在的试题";
}
if (newSubService.NewQuestion(ds) != 1)//这里调用了那个增加数据的方法
{
massage = "增加试题失败!";
}
else
{
massage = "增加试题成功!";
//newSubService.NewQuestion(
}
return massage;
}
}
谢谢你了啊` 浪费你这么长时间`